Skip to content

Commit

Permalink
test: remove private api usage in assertFixturesLoaded (#239)
Browse files Browse the repository at this point in the history
one place, which I omitted in #221
  • Loading branch information
slsyy authored Oct 29, 2024
1 parent 5205c2f commit 0d9033d
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions testfixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func testLoader(t *testing.T, db *sql.DB, dialect string, additionalOptions ...f
t.Errorf("cannot load fixtures: %v", err)
}

assertFixturesLoaded(t, l)
assertFixturesLoaded(t, db)
})

t.Run("LoadFromDirectory with SkipTableChecksumComputation", func(t *testing.T) {
Expand Down Expand Up @@ -151,7 +151,7 @@ func testLoader(t *testing.T, db *sql.DB, dialect string, additionalOptions ...f
t.Errorf("cannot load fixtures: %v", err)
}

assertFixturesLoaded(t, l)
assertFixturesLoaded(t, db)
})

t.Run("LoadFromDirectory-Multiple", func(t *testing.T) {
Expand All @@ -177,7 +177,7 @@ func testLoader(t *testing.T, db *sql.DB, dialect string, additionalOptions ...f
if err := l.Load(); err != nil {
t.Errorf("cannot load fixtures: %v", err)
}
assertFixturesLoaded(t, l)
assertFixturesLoaded(t, db)
})

t.Run("LoadFromFiles", func(t *testing.T) {
Expand Down Expand Up @@ -209,7 +209,7 @@ func testLoader(t *testing.T, db *sql.DB, dialect string, additionalOptions ...f
if err := l.Load(); err != nil {
t.Errorf("cannot load fixtures: %v", err)
}
assertFixturesLoaded(t, l)
assertFixturesLoaded(t, db)
})

t.Run("LoadFromFiles-Multiple", func(t *testing.T) {
Expand Down Expand Up @@ -243,7 +243,7 @@ func testLoader(t *testing.T, db *sql.DB, dialect string, additionalOptions ...f
if err := l.Load(); err != nil {
t.Errorf("cannot load fixtures: %v", err)
}
assertFixturesLoaded(t, l)
assertFixturesLoaded(t, db)
})

t.Run("LoadFromFiles-MultiTables", func(t *testing.T) {
Expand Down Expand Up @@ -274,7 +274,7 @@ func testLoader(t *testing.T, db *sql.DB, dialect string, additionalOptions ...f
if err := l.Load(); err != nil {
t.Errorf("cannot load fixtures: %v", err)
}
assertFixturesLoaded(t, l)
assertFixturesLoaded(t, db)
})

t.Run("LoadFromFiles-MultiTablesWithFS", func(t *testing.T) {
Expand Down Expand Up @@ -306,7 +306,7 @@ func testLoader(t *testing.T, db *sql.DB, dialect string, additionalOptions ...f
if err := l.Load(); err != nil {
t.Errorf("cannot load fixtures: %v", err)
}
assertFixturesLoaded(t, l)
assertFixturesLoaded(t, db)
})

t.Run("LoadFromDirectoryAndFiles", func(t *testing.T) {
Expand Down Expand Up @@ -335,7 +335,7 @@ func testLoader(t *testing.T, db *sql.DB, dialect string, additionalOptions ...f
if err := l.Load(); err != nil {
t.Errorf("cannot load fixtures: %v", err)
}
assertFixturesLoaded(t, l)
assertFixturesLoaded(t, db)
})

t.Run("LoadFromDirectoryAndFilesWithFS", func(t *testing.T) {
Expand Down Expand Up @@ -365,7 +365,7 @@ func testLoader(t *testing.T, db *sql.DB, dialect string, additionalOptions ...f
if err := l.Load(); err != nil {
t.Errorf("cannot load fixtures: %v", err)
}
assertFixturesLoaded(t, l)
assertFixturesLoaded(t, db)
})

t.Run("LoadFromPaths", func(t *testing.T) {
Expand Down Expand Up @@ -394,7 +394,7 @@ func testLoader(t *testing.T, db *sql.DB, dialect string, additionalOptions ...f
if err := l.Load(); err != nil {
t.Errorf("cannot load fixtures: %v", err)
}
assertFixturesLoaded(t, l)
assertFixturesLoaded(t, db)
})

t.Run("LoadFromPathsWithFS", func(t *testing.T) {
Expand Down Expand Up @@ -424,7 +424,7 @@ func testLoader(t *testing.T, db *sql.DB, dialect string, additionalOptions ...f
if err := l.Load(); err != nil {
t.Errorf("cannot load fixtures: %v", err)
}
assertFixturesLoaded(t, l)
assertFixturesLoaded(t, db)
})

t.Run("LoadFromPaths-OnlyFiles", func(t *testing.T) {
Expand Down Expand Up @@ -456,7 +456,7 @@ func testLoader(t *testing.T, db *sql.DB, dialect string, additionalOptions ...f
if err := l.Load(); err != nil {
t.Errorf("cannot load fixtures: %v", err)
}
assertFixturesLoaded(t, l)
assertFixturesLoaded(t, db)
})

t.Run("LoadFromPaths-OnlyDirs", func(t *testing.T) {
Expand Down Expand Up @@ -484,7 +484,7 @@ func testLoader(t *testing.T, db *sql.DB, dialect string, additionalOptions ...f
if err := l.Load(); err != nil {
t.Errorf("cannot load fixtures: %v", err)
}
assertFixturesLoaded(t, l)
assertFixturesLoaded(t, db)
})

t.Run("GenerateAndLoad", func(t *testing.T) {
Expand Down Expand Up @@ -549,20 +549,20 @@ func testLoader(t *testing.T, db *sql.DB, dialect string, additionalOptions ...f
})
}

func assertFixturesLoaded(t *testing.T, l *Loader) { //nolint
assertCount(t, l, "posts", 2)
assertCount(t, l, "comments", 4)
assertCount(t, l, "tags", 3)
assertCount(t, l, "posts_tags", 6)
assertCount(t, l, "users", 2)
assertCount(t, l, "assets", 1)
func assertFixturesLoaded(t *testing.T, db *sql.DB) { //nolint
assertCount(t, db, "posts", 2)
assertCount(t, db, "comments", 4)
assertCount(t, db, "tags", 3)
assertCount(t, db, "posts_tags", 6)
assertCount(t, db, "users", 2)
assertCount(t, db, "assets", 1)
}

func assertCount(t *testing.T, l *Loader, table string, expectedCount int) { //nolint
func assertCount(t *testing.T, db *sql.DB, table string, expectedCount int) { //nolint
count := 0
sql := fmt.Sprintf("SELECT COUNT(*) FROM %s", table)

row := l.db.QueryRow(sql)
row := db.QueryRow(sql)
if err := row.Scan(&count); err != nil {
t.Errorf("cannot query table: %v", err)
}
Expand Down

0 comments on commit 0d9033d

Please sign in to comment.