fix tests for app

This commit is contained in:
Simon Vieille 2024-03-31 22:19:58 +02:00
parent 83682511b3
commit 40d474b6eb
Signed by: deblan
GPG key ID: 579388D585F70417

View file

@ -2,7 +2,9 @@ package app
import ( import (
"database/sql" "database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
"gitnet.fr/deblan/database-anonymizer/config" "gitnet.fr/deblan/database-anonymizer/config"
"gitnet.fr/deblan/database-anonymizer/faker" "gitnet.fr/deblan/database-anonymizer/faker"
"testing" "testing"
@ -47,30 +49,30 @@ func TestAppDoAction(t *testing.T) {
func TestAppRun(t *testing.T) { func TestAppRun(t *testing.T) {
schema, _ := config.LoadSchemaConfigFromFile("../tests/schema.yml") schema, _ := config.LoadSchemaConfigFromFile("../tests/schema.yml")
dsns := []string{ dsns := make(map[string]string)
"mysql://root:root@tcp(service-mysql)/test", dsns["mysql"] = "mysql://root:root@tcp(service-mysql)/test"
// "postgres://postgres@tcp(service-postgres)/test", dsns["postgres"] = "postgres://postgres:postgres@service-postgres:5432/test?sslmode=disable"
}
for _, dsn := range dsns { var count int
for dbtype, dsn := range dsns {
databaseConfig, _ := config.LoadDatabaseConfig(dsn) databaseConfig, _ := config.LoadDatabaseConfig(dsn)
db, _ := sql.Open(databaseConfig.Type, databaseConfig.Dsn) db, _ := sql.Open(databaseConfig.Type, databaseConfig.Dsn)
app := App{} app := App{}
app.Run(db, schema, faker.NewFakeManager(), databaseConfig) app.Run(db, schema, faker.NewFakeManager(), databaseConfig)
var count int
row := db.QueryRow("SELECT COUNT(*) FROM table_truncate1") row := db.QueryRow("SELECT COUNT(*) FROM table_truncate1")
row.Scan(&count) row.Scan(&count)
if count != 0 { if count != 0 {
t.Fatalf("TestAppRuny: table_truncate1 check failed") t.Fatalf(fmt.Sprintf("TestAppRuny: table_truncate1 check failed (%s)", dbtype))
} }
row = db.QueryRow("SELECT COUNT(*) FROM table_truncate2") row = db.QueryRow("SELECT COUNT(*) FROM table_truncate2")
row.Scan(&count) row.Scan(&count)
if count != 1 { if count != 1 {
t.Fatalf("TestAppRuny: table_truncate2 check failed") t.Fatalf(fmt.Sprintf("TestAppRuny: table_truncate2 check failed (%s)", dbtype))
} }
} }
} }