|
7 | 7 | "database/sql" |
8 | 8 | "embed" |
9 | 9 | "io/fs" |
| 10 | + "log/slog" |
10 | 11 | "os" |
11 | 12 | "testing" |
12 | 13 |
|
@@ -330,3 +331,39 @@ func TestMigrationIsValid(t *testing.T) { |
330 | 331 | assert.ErrorIs(t, err, v.err, "error is wrong for test %v", k) |
331 | 332 | } |
332 | 333 | } |
| 334 | + |
| 335 | +func TestMigrationWithLogger(t *testing.T) { |
| 336 | + l := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{ |
| 337 | + Level: slog.LevelWarn, |
| 338 | + })) |
| 339 | + |
| 340 | + morpher, err := NewMorpher( |
| 341 | + WithDialect(DialectSQLite()), |
| 342 | + WithMigrationFromFile("testData/01_base_table.sql"), |
| 343 | + WithLog(l), |
| 344 | + ) |
| 345 | + |
| 346 | + assert.NoError(t, err, "morpher could not be created") |
| 347 | + assert.Equal(t, l, morpher.Log, "logger was not set correctly") |
| 348 | +} |
| 349 | + |
| 350 | +func TestMigrationWithTableNameValid(t *testing.T) { |
| 351 | + morpher, err := NewMorpher( |
| 352 | + WithDialect(DialectSQLite()), |
| 353 | + WithMigrationFromFile("testData/01_base_table.sql"), |
| 354 | + WithTableName("dimorphodon"), |
| 355 | + ) |
| 356 | + |
| 357 | + assert.NoError(t, err, "morpher could not be created") |
| 358 | + assert.Equal(t, "dimorphodon", morpher.TableName, "table name was not set correctly") |
| 359 | +} |
| 360 | + |
| 361 | +func TestMigrationWithTableNameInvalid(t *testing.T) { |
| 362 | + _, err := NewMorpher( |
| 363 | + WithDialect(DialectSQLite()), |
| 364 | + WithMigrationFromFile("testData/01_base_table.sql"), |
| 365 | + WithTableName("di/mor/pho/don"), |
| 366 | + ) |
| 367 | + |
| 368 | + assert.Error(t, err, "morpher could created with invalid table name") |
| 369 | +} |
0 commit comments