diff options
| author | Brad Fitzpatrick <brad@danga.com> | 2010-05-19 17:48:53 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <brad@danga.com> | 2010-05-19 17:48:53 -0700 |
| commit | af486cb23fca3b3b47a698b6bc7be637f80597a0 (patch) | |
| tree | b8bb687775f9f99701316b446ce673f292eeed9b /src/pkg/os/os_test.go | |
| parent | 94b3292622846b33dafe15d32d2b20cd2ce1fbef (diff) | |
| download | golang-af486cb23fca3b3b47a698b6bc7be637f80597a0.tar.gz | |
os: add Chtimes function
R=rsc, r
CC=golang-dev
http://codereview.appspot.com/1103041
Committer: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/pkg/os/os_test.go')
| -rw-r--r-- | src/pkg/os/os_test.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/pkg/os/os_test.go b/src/pkg/os/os_test.go index 5fb599265..b2332f0c8 100644 --- a/src/pkg/os/os_test.go +++ b/src/pkg/os/os_test.go @@ -483,6 +483,48 @@ func TestTruncate(t *testing.T) { Remove(Path) } +func TestChtimes(t *testing.T) { + MkdirAll("_obj", 0777) + const Path = "_obj/_TestChtimes_" + fd, err := Open(Path, O_WRONLY|O_CREAT, 0666) + if err != nil { + t.Fatalf("create %s: %s", Path, err) + } + fd.Write([]byte("hello, world\n")) + fd.Close() + + preStat, err := Stat(Path) + if err != nil { + t.Fatalf("Stat %s: %s", Path, err) + } + + // Move access and modification time back a second + const OneSecond = 1e9 // in nanoseconds + err = Chtimes(Path, preStat.Atime_ns-OneSecond, preStat.Mtime_ns-OneSecond) + if err != nil { + t.Fatalf("Chtimes %s: %s", Path, err) + } + + postStat, err := Stat(Path) + if err != nil { + t.Fatalf("second Stat %s: %s", Path, err) + } + + if postStat.Atime_ns >= preStat.Atime_ns { + t.Errorf("Atime_ns didn't go backwards; was=%d, after=%d", + preStat.Atime_ns, + postStat.Atime_ns) + } + + if postStat.Mtime_ns >= preStat.Mtime_ns { + t.Errorf("Mtime_ns didn't go backwards; was=%d, after=%d", + preStat.Mtime_ns, + postStat.Mtime_ns) + } + + Remove(Path) +} + func TestChdirAndGetwd(t *testing.T) { fd, err := Open(".", O_RDONLY, 0) if err != nil { |
