summaryrefslogtreecommitdiff
path: root/pkg/ctime/ctime_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/ctime/ctime_test.go')
-rw-r--r--pkg/ctime/ctime_test.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/pkg/ctime/ctime_test.go b/pkg/ctime/ctime_test.go
new file mode 100644
index 000000000..abfc627da
--- /dev/null
+++ b/pkg/ctime/ctime_test.go
@@ -0,0 +1,63 @@
+package ctime
+
+import (
+ "io/ioutil"
+ "os"
+ "testing"
+ "time"
+)
+
+func TestCreated(t *testing.T) {
+ before := time.Now()
+
+ fileA, err := ioutil.TempFile("", "ctime-test-")
+ if err != nil {
+ t.Error(err)
+ }
+ defer os.Remove(fileA.Name())
+
+ fileB, err := ioutil.TempFile("", "ctime-test-")
+ if err != nil {
+ t.Error(err)
+ }
+ defer os.Remove(fileB.Name())
+
+ after := time.Now()
+
+ infoA, err := fileA.Stat()
+ if err != nil {
+ t.Error(err)
+ }
+
+ err = fileA.Close()
+ if err != nil {
+ t.Error(err)
+ }
+
+ infoB, err := fileB.Stat()
+ if err != nil {
+ t.Error(err)
+ }
+
+ err = fileB.Close()
+ if err != nil {
+ t.Error(err)
+ }
+
+ createdA := Created(infoA)
+ beforeToCreateA := createdA.Sub(before)
+ if beforeToCreateA.Nanoseconds() < -1000000000 {
+ t.Errorf("created file A %s is %v nanoseconds before %s", createdA, -beforeToCreateA.Nanoseconds(), before)
+ }
+
+ createdB := Created(infoB)
+ createAToCreateB := createdB.Sub(createdA)
+ if createAToCreateB.Nanoseconds() < 0 {
+ t.Errorf("created file B %s is %v nanoseconds before file A %s", createdB, -createAToCreateB.Nanoseconds(), createdA)
+ }
+
+ createBToAfter := after.Sub(createdB)
+ if createBToAfter.Nanoseconds() < 0 {
+ t.Errorf("created file B %s is %v nanoseconds after %s", createdB, -createBToAfter.Nanoseconds(), after)
+ }
+}