diff --git a/dguta/dguta_test.go b/dguta/dguta_test.go index 91082d04..ed713c06 100644 --- a/dguta/dguta_test.go +++ b/dguta/dguta_test.go @@ -98,7 +98,8 @@ func TestDGUTA(t *testing.T) { }) }) - dgutaData, expectedRootGUTAs, expected, expectedKeys := testData(t) + refUnixTime := time.Now().Unix() + dgutaData, expectedRootGUTAs, expected, expectedKeys := testData(t, refUnixTime) Convey("You can see if a GUTA passes a filter", t, func() { numGutas := 17 @@ -588,10 +589,11 @@ type gutaInfo struct { } // testData provides some test data and expected results. -func testData(t *testing.T) (dgutaData string, expectedRootGUTAs GUTAs, expected []*DGUTA, expectedKeys []string) { +func testData(t *testing.T, refUnixTime int64) (dgutaData string, expectedRootGUTAs GUTAs, + expected []*DGUTA, expectedKeys []string) { t.Helper() - dgutaData = internaldata.TestDGUTAData(t, internaldata.CreateDefaultTestData(1, 2, 1, 101, 102)) + dgutaData = internaldata.TestDGUTAData(t, internaldata.CreateDefaultTestData(1, 2, 1, 101, 102, refUnixTime)) orderOfOldAges := []summary.DirGUTAge{ summary.DGUTAgeAll, summary.DGUTAgeA1M, summary.DGUTAgeM2M, diff --git a/dguta/tree_test.go b/dguta/tree_test.go index 90087fc4..266681ee 100644 --- a/dguta/tree_test.go +++ b/dguta/tree_test.go @@ -41,6 +41,8 @@ import ( func TestTree(t *testing.T) { expectedFTsBam := []summary.DirGUTAFileType{summary.DGUTAFileTypeBam} + refUnixTime := time.Now().Unix() + Convey("You can make a Tree from a dguta database", t, func() { paths, err := testMakeDBPaths(t) So(err, ShouldBeNil) @@ -49,7 +51,7 @@ func TestTree(t *testing.T) { So(errc, ShouldNotBeNil) So(tree, ShouldBeNil) - errc = testCreateDB(t, paths[0]) + errc = testCreateDB(t, paths[0], refUnixTime) So(errc, ShouldBeNil) tree, errc = NewTree(paths[0]) @@ -70,7 +72,7 @@ func TestTree(t *testing.T) { expectedFTsCramAndDir := []summary.DirGUTAFileType{summary.DGUTAFileTypeCram, summary.DGUTAFileTypeDir} expectedAtime := time.Unix(50, 0) expectedAtimeG := time.Unix(60, 0) - expectedMtime := time.Unix(time.Now().Unix()-(summary.SecondsInAYear*3), 0) + expectedMtime := time.Unix(refUnixTime-(summary.SecondsInAYear*3), 0) const numDirectories = 10 @@ -378,10 +380,10 @@ func TestTree(t *testing.T) { }) } -func testCreateDB(t *testing.T, path string) error { +func testCreateDB(t *testing.T, path string, refUnixTime int64) error { t.Helper() - dgutData := internaldata.TestDGUTAData(t, internaldata.CreateDefaultTestData(1, 2, 1, 101, 102)) + dgutData := internaldata.TestDGUTAData(t, internaldata.CreateDefaultTestData(1, 2, 1, 101, 102, refUnixTime)) data := strings.NewReader(dgutData) db := NewDB(path) diff --git a/internal/data/data.go b/internal/data/data.go index 76d3d453..c7914ef5 100644 --- a/internal/data/data.go +++ b/internal/data/data.go @@ -60,7 +60,7 @@ type TestFile struct { ATime, MTime int } -func CreateDefaultTestData(gidA, gidB, gidC, uidA, uidB int) []TestFile { +func CreateDefaultTestData(gidA, gidB, gidC, uidA, uidB int, refUnixTime int64) []TestFile { dir := "/" abdf := filepath.Join(dir, "a", "b", "d", "f") abdg := filepath.Join(dir, "a", "b", "d", "g") @@ -126,8 +126,8 @@ func CreateDefaultTestData(gidA, gidB, gidC, uidA, uidB int) []TestFile { SizeOfEachFile: 1, GID: 3, UID: 103, - ATime: int(time.Now().Unix() - summary.SecondsInAYear), - MTime: int(time.Now().Unix() - (summary.SecondsInAYear * 3)), + ATime: int(refUnixTime - summary.SecondsInAYear), + MTime: int(refUnixTime - (summary.SecondsInAYear * 3)), }, } diff --git a/internal/db/dguta.go b/internal/db/dguta.go index 7dc9a628..b52f430d 100644 --- a/internal/db/dguta.go +++ b/internal/db/dguta.go @@ -49,7 +49,7 @@ const exampleDBBatchSize = 20 // CreateExampleDGUTADB creates a temporary dguta.db from some example data that // uses your uid and 2 of your gids, and returns the path to the database // directory. For use when testing something that needs a Tree. -func CreateExampleDGUTADB(t *testing.T) (string, error) { +func CreateExampleDGUTADB(t *testing.T, refUnixTime int64) (string, error) { t.Helper() _, uid, gids := GetUserAndGroups(t) @@ -57,16 +57,16 @@ func CreateExampleDGUTADB(t *testing.T) (string, error) { gids = append(gids, "0") } - return CreateExampleDGUTADBCustomIDs(t, uid, gids[0], gids[1]) + return CreateExampleDGUTADBCustomIDs(t, uid, gids[0], gids[1], refUnixTime) } // CreateExampleDGUTADBCustomIDs creates a temporary dguta.db from some example // data that uses the given uid and gids, and returns the path to the database // directory. -func CreateExampleDGUTADBCustomIDs(t *testing.T, uid, gidA, gidB string) (string, error) { +func CreateExampleDGUTADBCustomIDs(t *testing.T, uid, gidA, gidB string, refUnixTime int64) (string, error) { t.Helper() - dgutaData := exampleDGUTAData(t, uid, gidA, gidB) + dgutaData := exampleDGUTAData(t, uid, gidA, gidB, refUnixTime) return CreateCustomDGUTADB(t, dgutaData) } @@ -103,7 +103,7 @@ func createExampleDgutaDir(t *testing.T) (string, error) { // exampleDGUTAData is some example DGUTA data that uses the given uid and gids, // along with root's uid. -func exampleDGUTAData(t *testing.T, uidStr, gidAStr, gidBStr string) string { +func exampleDGUTAData(t *testing.T, uidStr, gidAStr, gidBStr string, refUnixTime int64) string { t.Helper() uid, err := strconv.ParseUint(uidStr, 10, 64) @@ -121,7 +121,7 @@ func exampleDGUTAData(t *testing.T, uidStr, gidAStr, gidBStr string) string { t.Fatal(err) } - return internaldata.TestDGUTAData(t, internaldata.CreateDefaultTestData(int(gidA), int(gidB), 0, int(uid), 0)) + return internaldata.TestDGUTAData(t, internaldata.CreateDefaultTestData(int(gidA), int(gidB), 0, int(uid), 0, refUnixTime)) } func CreateDGUTADBFromFakeFiles(t *testing.T, files []internaldata.TestFile,