audit full project flows and harden backend
This commit is contained in:
@@ -1,18 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"gorm.io/driver/sqlite"
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func TestPrepareAdditiveMigrationsSkipsMissingLegacyTable(t *testing.T) {
|
||||
databaseService, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
|
||||
sqlDatabase, mock, err := sqlmock.New()
|
||||
if err != nil {
|
||||
t.Fatalf("open sqlite database: %v", err)
|
||||
t.Fatalf("open sql mock: %v", err)
|
||||
}
|
||||
defer sqlDatabase.Close()
|
||||
mock.ExpectQuery(regexp.QuoteMeta("SELECT count(*) FROM information_schema.tables WHERE table_schema = CURRENT_SCHEMA() AND table_name = $1 AND table_type = $2")).
|
||||
WithArgs("gasorder_track_point", "BASE TABLE").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"count"}).AddRow(0))
|
||||
databaseService, err := gorm.Open(postgres.New(postgres.Config{Conn: sqlDatabase}), &gorm.Config{})
|
||||
if err != nil {
|
||||
t.Fatalf("open postgres mock: %v", err)
|
||||
}
|
||||
if err := prepareAdditiveMigrations(databaseService, "postgres"); err != nil {
|
||||
t.Fatalf("missing legacy table should not require a backfill: %v", err)
|
||||
}
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Fatalf("unexpected migration query: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user