Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rk1274 committed Nov 1, 2024
1 parent 30cdfab commit e6ab26e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
8 changes: 5 additions & 3 deletions dguta/dguta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions dguta/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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])
Expand All @@ -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

Expand Down Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions internal/data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)),
},
}

Expand Down
12 changes: 6 additions & 6 deletions internal/db/dguta.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,24 @@ 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)
if len(gids) < minGIDsForExampleDgutaDB {
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)
}
Expand Down Expand Up @@ -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)
Expand All @@ -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))

Check failure on line 124 in internal/db/dguta.go

View workflow job for this annotation

GitHub Actions / lint

line is 124 characters (lll)
}

func CreateDGUTADBFromFakeFiles(t *testing.T, files []internaldata.TestFile,
Expand Down

0 comments on commit e6ab26e

Please sign in to comment.