|
| 1 | +package iDB |
| 2 | + |
| 3 | +import ( |
| 4 | + //"os" |
| 5 | + "testing" |
| 6 | + . "github.com/remogatto/prettytest" |
| 7 | +) |
| 8 | + |
| 9 | + |
| 10 | +type utilsSuite struct { |
| 11 | + Suite |
| 12 | + testfile string |
| 13 | +} |
| 14 | + |
| 15 | +func (suite *utilsSuite) Before() { |
| 16 | + suite.testfile = "mytestfile" |
| 17 | +} |
| 18 | + |
| 19 | +func (Suite *utilsSuite) After() { |
| 20 | + os.Remove(Suite.testfile) |
| 21 | +} |
| 22 | + |
| 23 | +const testfile = "mytestfile" |
| 24 | + |
| 25 | +func Test_SetXatrr(t *testing.T){ //test function starts with "Test" and takes a pointer to type testing.T |
| 26 | + err := SetXattr(testfile, "mykey", "myvalue23") |
| 27 | + if (err != nil || !IsXattrExists(testfile, "mykey")) { //try a unit test on function |
| 28 | + t.Error("SetXattr did not work as expected. Error:", err) // log error if it did not work as expected |
| 29 | + } else { |
| 30 | + t.Log("one test passed.") // log some info if you want |
| 31 | + } |
| 32 | +} |
| 33 | +func Test_GetXatrr(t *testing.T){ |
| 34 | + Test_SetXatrr(t) |
| 35 | + result, err := GetXattr(testfile, "mykey") |
| 36 | + if (result != "myvalue23") { //try a unit test on function |
| 37 | + t.Error("GetXattr did not work as expected. Error:", err) // log error if it did not work as expected |
| 38 | + } else { |
| 39 | + t.Log("one test passed.") // log some info if you want |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +func Test_FileIsExists(t *testing.T){ |
| 44 | + result, err := FileIsExists(testfile) |
| 45 | + if !result { |
| 46 | + t.Error("FileIsExists did not work as expected, Error:", err) |
| 47 | + } else { |
| 48 | + t.Log("one test passed") |
| 49 | + } |
| 50 | +} |
0 commit comments