Skip to content

Commit 3052db5

Browse files
committed
More tests.
1 parent 2fe8076 commit 3052db5

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

migration_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"database/sql"
88
"embed"
99
"io/fs"
10+
"log/slog"
1011
"os"
1112
"testing"
1213

@@ -330,3 +331,39 @@ func TestMigrationIsValid(t *testing.T) {
330331
assert.ErrorIs(t, err, v.err, "error is wrong for test %v", k)
331332
}
332333
}
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

Comments
 (0)