12 // TestChtimesLinux tests Chtimes access time on a tempfile on Linux
13 func TestChtimesLinux(t *testing.T) {
14 file, dir := prepareTempFile(t)
15 defer os.RemoveAll(dir)
17 beforeUnixEpochTime := time.Unix(0, 0).Add(-100 * time.Second)
18 unixEpochTime := time.Unix(0, 0)
19 afterUnixEpochTime := time.Unix(100, 0)
20 unixMaxTime := maxTime
22 // Test both aTime and mTime set to Unix Epoch
23 Chtimes(file, unixEpochTime, unixEpochTime)
25 f, err := os.Stat(file)
30 stat := f.Sys().(*syscall.Stat_t)
31 aTime := time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
32 if aTime != unixEpochTime {
33 t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime)
36 // Test aTime before Unix Epoch and mTime set to Unix Epoch
37 Chtimes(file, beforeUnixEpochTime, unixEpochTime)
39 f, err = os.Stat(file)
44 stat = f.Sys().(*syscall.Stat_t)
45 aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
46 if aTime != unixEpochTime {
47 t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime)
50 // Test aTime set to Unix Epoch and mTime before Unix Epoch
51 Chtimes(file, unixEpochTime, beforeUnixEpochTime)
53 f, err = os.Stat(file)
58 stat = f.Sys().(*syscall.Stat_t)
59 aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
60 if aTime != unixEpochTime {
61 t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime)
64 // Test both aTime and mTime set to after Unix Epoch (valid time)
65 Chtimes(file, afterUnixEpochTime, afterUnixEpochTime)
67 f, err = os.Stat(file)
72 stat = f.Sys().(*syscall.Stat_t)
73 aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
74 if aTime != afterUnixEpochTime {
75 t.Fatalf("Expected: %s, got: %s", afterUnixEpochTime, aTime)
78 // Test both aTime and mTime set to Unix max time
79 Chtimes(file, unixMaxTime, unixMaxTime)
81 f, err = os.Stat(file)
86 stat = f.Sys().(*syscall.Stat_t)
87 aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
88 if aTime.Truncate(time.Second) != unixMaxTime.Truncate(time.Second) {
89 t.Fatalf("Expected: %s, got: %s", unixMaxTime.Truncate(time.Second), aTime.Truncate(time.Second))