|
@@ -19,72 +19,92 @@ func TestChtimesATime(t *testing.T) {
|
|
|
afterUnixEpochTime := unixEpochTime.Add(100 * time.Second)
|
|
|
|
|
|
// Test both aTime and mTime set to Unix Epoch
|
|
|
- Chtimes(file, unixEpochTime, unixEpochTime)
|
|
|
-
|
|
|
- f, err := os.Stat(file)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
-
|
|
|
- stat := f.Sys().(*syscall.Stat_t)
|
|
|
- aTime := time.Unix(stat.Atim.Unix())
|
|
|
- if aTime != unixEpochTime {
|
|
|
- t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime)
|
|
|
- }
|
|
|
+ t.Run("both aTime and mTime set to Unix Epoch", func(t *testing.T) {
|
|
|
+ if err := Chtimes(file, unixEpochTime, unixEpochTime); err != nil {
|
|
|
+ t.Error(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ f, err := os.Stat(file)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ stat := f.Sys().(*syscall.Stat_t)
|
|
|
+ aTime := time.Unix(stat.Atim.Unix())
|
|
|
+ if aTime != unixEpochTime {
|
|
|
+ t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime)
|
|
|
+ }
|
|
|
+ })
|
|
|
|
|
|
// Test aTime before Unix Epoch and mTime set to Unix Epoch
|
|
|
- Chtimes(file, beforeUnixEpochTime, unixEpochTime)
|
|
|
-
|
|
|
- f, err = os.Stat(file)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
-
|
|
|
- stat = f.Sys().(*syscall.Stat_t)
|
|
|
- aTime = time.Unix(stat.Atim.Unix())
|
|
|
- if aTime != unixEpochTime {
|
|
|
- t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime)
|
|
|
- }
|
|
|
+ t.Run("aTime before Unix Epoch and mTime set to Unix Epoch", func(t *testing.T) {
|
|
|
+ if err := Chtimes(file, beforeUnixEpochTime, unixEpochTime); err != nil {
|
|
|
+ t.Error(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ f, err := os.Stat(file)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ stat := f.Sys().(*syscall.Stat_t)
|
|
|
+ aTime := time.Unix(stat.Atim.Unix())
|
|
|
+ if aTime != unixEpochTime {
|
|
|
+ t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime)
|
|
|
+ }
|
|
|
+ })
|
|
|
|
|
|
// Test aTime set to Unix Epoch and mTime before Unix Epoch
|
|
|
- Chtimes(file, unixEpochTime, beforeUnixEpochTime)
|
|
|
-
|
|
|
- f, err = os.Stat(file)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
-
|
|
|
- stat = f.Sys().(*syscall.Stat_t)
|
|
|
- aTime = time.Unix(stat.Atim.Unix())
|
|
|
- if aTime != unixEpochTime {
|
|
|
- t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime)
|
|
|
- }
|
|
|
+ t.Run("aTime set to Unix Epoch and mTime before Unix Epoch", func(t *testing.T) {
|
|
|
+ if err := Chtimes(file, unixEpochTime, beforeUnixEpochTime); err != nil {
|
|
|
+ t.Error(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ f, err := os.Stat(file)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ stat := f.Sys().(*syscall.Stat_t)
|
|
|
+ aTime := time.Unix(stat.Atim.Unix())
|
|
|
+ if aTime != unixEpochTime {
|
|
|
+ t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime)
|
|
|
+ }
|
|
|
+ })
|
|
|
|
|
|
// Test both aTime and mTime set to after Unix Epoch (valid time)
|
|
|
- Chtimes(file, afterUnixEpochTime, afterUnixEpochTime)
|
|
|
-
|
|
|
- f, err = os.Stat(file)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
-
|
|
|
- stat = f.Sys().(*syscall.Stat_t)
|
|
|
- aTime = time.Unix(stat.Atim.Unix())
|
|
|
- if aTime != afterUnixEpochTime {
|
|
|
- t.Fatalf("Expected: %s, got: %s", afterUnixEpochTime, aTime)
|
|
|
- }
|
|
|
+ t.Run("both aTime and mTime set to after Unix Epoch (valid time)", func(t *testing.T) {
|
|
|
+ if err := Chtimes(file, afterUnixEpochTime, afterUnixEpochTime); err != nil {
|
|
|
+ t.Error(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ f, err := os.Stat(file)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ stat := f.Sys().(*syscall.Stat_t)
|
|
|
+ aTime := time.Unix(stat.Atim.Unix())
|
|
|
+ if aTime != afterUnixEpochTime {
|
|
|
+ t.Fatalf("Expected: %s, got: %s", afterUnixEpochTime, aTime)
|
|
|
+ }
|
|
|
+ })
|
|
|
|
|
|
// Test both aTime and mTime set to Unix max time
|
|
|
- Chtimes(file, unixMaxTime, unixMaxTime)
|
|
|
-
|
|
|
- f, err = os.Stat(file)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
-
|
|
|
- stat = f.Sys().(*syscall.Stat_t)
|
|
|
- aTime = time.Unix(stat.Atim.Unix())
|
|
|
- if aTime.Truncate(time.Second) != unixMaxTime.Truncate(time.Second) {
|
|
|
- t.Fatalf("Expected: %s, got: %s", unixMaxTime.Truncate(time.Second), aTime.Truncate(time.Second))
|
|
|
- }
|
|
|
+ t.Run("both aTime and mTime set to Unix max time", func(t *testing.T) {
|
|
|
+ if err := Chtimes(file, unixMaxTime, unixMaxTime); err != nil {
|
|
|
+ t.Error(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ f, err := os.Stat(file)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ stat := f.Sys().(*syscall.Stat_t)
|
|
|
+ aTime := time.Unix(stat.Atim.Unix())
|
|
|
+ if aTime.Truncate(time.Second) != unixMaxTime.Truncate(time.Second) {
|
|
|
+ t.Fatalf("Expected: %s, got: %s", unixMaxTime.Truncate(time.Second), aTime.Truncate(time.Second))
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|