unix: fix TestUtimesNanoAt for filesystems with 1-second resolution time stamps

Some file systems don't support sub-second time stamp resolution. Handle
these correctly by only checking nanoseconds in case Mtim.Nsec is zero.

Fixes golang/go#26034

Change-Id: I1ab400b8e09b5cfdac6b70a33f676770a48180b1
Reviewed-on: https://go-review.googlesource.com/120816
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: jimmy frasche <soapboxcicero@gmail.com>
This commit is contained in:
Tobias Klauser
2018-06-26 08:41:42 +02:00
committed by Brad Fitzpatrick
parent a200a19cb9
commit c4afb3effa

View File

@@ -142,8 +142,14 @@ func TestUtimesNanoAt(t *testing.T) {
}
// Only check Mtim, Atim might not be supported by the underlying filesystem
if st.Mtim != ts[1] {
t.Errorf("UtimesNanoAt: wrong mtime: %v", st.Mtim)
expected := ts[1]
if st.Mtim.Nsec == 0 {
// Some filesystems only support 1-second time stamp resolution
// and will always set Nsec to 0.
expected.Nsec = 0
}
if st.Mtim != expected {
t.Errorf("UtimesNanoAt: wrong mtime: expected %v, got %v", expected, st.Mtim)
}
}