tests: TestUtimesNano: replace ugly compareUtimes wrapper

This commit is contained in:
Jakob Unterwurzacher 2018-03-05 22:22:35 +01:00
parent 3064d72b97
commit 426b9536df
1 changed files with 16 additions and 14 deletions

View File

@ -686,7 +686,7 @@ func TestLchown(t *testing.T) {
} }
// Set nanoseconds by path, symlink // Set nanoseconds by path, symlink
func TestUtimesNanoSymlink(t *testing.T) { func Symlink(t *testing.T) {
if runtime.GOOS == "darwin" { if runtime.GOOS == "darwin" {
t.Skipf("MacOS \"touch\" does not support \"--no-dereference\"") t.Skipf("MacOS \"touch\" does not support \"--no-dereference\"")
} }
@ -713,17 +713,15 @@ type utimesTestcaseStruct struct {
out [2]syscall.Timespec out [2]syscall.Timespec
} }
func compareUtimes(want [2]syscall.Timespec, actual [2]syscall.Timespec) error { // compareTimespec return true if the two passed Timespec are identical.
tsNames := []string{"atime", "mtime"} func compareTimespec(want syscall.Timespec, actual syscall.Timespec) bool {
for i := range want { if want.Sec != actual.Sec {
if want[i].Sec != actual[i].Sec { return false
return fmt.Errorf("Wrong %s seconds: want=%d actual=%d", tsNames[i], want[i].Sec, actual[i].Sec)
}
if want[i].Nsec != actual[i].Nsec {
return fmt.Errorf("Wrong %s nanoseconds: want=%d actual=%d", tsNames[i], want[i].Nsec, actual[i].Nsec)
}
} }
return nil if want.Nsec != actual.Nsec {
return false
}
return true
} }
const _UTIME_OMIT = ((1 << 30) - 2) const _UTIME_OMIT = ((1 << 30) - 2)
@ -759,9 +757,13 @@ func doTestUtimesNano(t *testing.T, path string) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
err = compareUtimes(tc.out, extractAtimeMtime(st)) want := tc.out
if err != nil { have := extractAtimeMtime(st)
t.Errorf("Testcase %d: %v", i, err) if !compareTimespec(want[0], have[0]) {
t.Errorf("Testcase %d: atime: want=%+v, have=%+v", i, want[0], have[0])
}
if !compareTimespec(want[1], have[1]) {
t.Errorf("Testcase %d: mtime: want=%+v, have=%+v", i, want[1], have[1])
} }
} }
} }