aboutsummaryrefslogtreecommitdiffstats
path: root/internal/configloader/configloader_test.go
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2024-08-18 14:51:00 -0400
committerGitHub <noreply@github.com>2024-08-18 14:51:00 -0400
commitd2186ed58d907a81648aa62ffa17ec20fb2d213e (patch)
treea5b2e26f1f96f333d48a8b20126ecc9ead697029 /internal/configloader/configloader_test.go
parentMultiple issue fixes in readme (#3) (diff)
downloadcli-d2186ed58d907a81648aa62ffa17ec20fb2d213e.zip
GH-4: Add configurable migrations table name (#6)
* Add configurable migrations table name * Update codecov to be informational * Add mockdb and couple of extra tests * remove extra files * Add list query error test * Add readme update for custom migration table
Diffstat (limited to 'internal/configloader/configloader_test.go')
-rw-r--r--internal/configloader/configloader_test.go46
1 files changed, 28 insertions, 18 deletions
diff --git a/internal/configloader/configloader_test.go b/internal/configloader/configloader_test.go
index 89c4368..352f243 100644
--- a/internal/configloader/configloader_test.go
+++ b/internal/configloader/configloader_test.go
@@ -19,6 +19,7 @@ func TestNewConfigDefaults(t *testing.T) {
check.Equal(t, cfg.Migrations.DirectoryPath, "migrations")
check.Equal(t, cfg.Migrations.VersionStyle, configloader.VersionStyleTimestamp)
+ check.Equal(t, cfg.Connection.MigrationsTable, "bolt_migrations")
}
func TestNewConfigWithInvalidVersionStyle(t *testing.T) {
@@ -41,6 +42,7 @@ func TestNewConfigFindsFileAndPopulatesConfigStruct(t *testing.T) {
bolttest.UnsetEnv(t, "BOLT_DB_PASSWORD")
bolttest.UnsetEnv(t, "BOLT_DB_NAME")
bolttest.UnsetEnv(t, "BOLT_DB_DRIVER")
+ bolttest.UnsetEnv(t, "BOLT_DB_MIGRATIONS_TABLE")
bolttest.UnsetEnv(t, "BOLT_MIGRATIONS_DIR_PATH")
bolttest.UnsetEnv(t, "BOLT_MIGRATIONS_VERSION_STYLE")
expectedCfg := configloader.Config{
@@ -49,12 +51,13 @@ func TestNewConfigFindsFileAndPopulatesConfigStruct(t *testing.T) {
VersionStyle: configloader.VersionStyleSequential,
},
Connection: configloader.ConnectionConfig{
- Host: "testhost",
- Port: "1234",
- User: "testuser",
- Password: "testpassword",
- DBName: "testdb",
- Driver: "postgresql",
+ Host: "testhost",
+ Port: "1234",
+ User: "testuser",
+ Password: "testpassword",
+ DBName: "testdb",
+ Driver: "postgresql",
+ MigrationsTable: "test_table",
},
}
tmpdir := t.TempDir()
@@ -74,12 +77,13 @@ func TestNewConfigCanBeOverridenByEnvVars(t *testing.T) {
VersionStyle: configloader.VersionStyleSequential,
},
Connection: configloader.ConnectionConfig{
- Host: "testhost",
- Port: "1234",
- User: "testuser",
- Password: "testpassword",
- DBName: "testdb",
- Driver: "mysql",
+ Host: "testhost",
+ Port: "1234",
+ User: "testuser",
+ Password: "testpassword",
+ DBName: "testdb",
+ Driver: "mysql",
+ MigrationsTable: "test_table",
},
}
bolttest.CreateConfigFile(t, &fileCfg, "bolt.toml")
@@ -90,12 +94,13 @@ func TestNewConfigCanBeOverridenByEnvVars(t *testing.T) {
VersionStyle: configloader.VersionStyleTimestamp,
},
Connection: configloader.ConnectionConfig{
- Host: "envtesthost",
- Port: "4321",
- User: "envtestuser",
- Password: "envtestpassword",
- DBName: "envtestdb",
- Driver: "postgresql",
+ Host: "envtesthost",
+ Port: "4321",
+ User: "envtestuser",
+ Password: "envtestpassword",
+ DBName: "envtestdb",
+ Driver: "postgresql",
+ MigrationsTable: "different_table",
},
}
t.Setenv("BOLT_MIGRATIONS_VERSION_STYLE", string(envCfg.Migrations.VersionStyle))
@@ -106,6 +111,7 @@ func TestNewConfigCanBeOverridenByEnvVars(t *testing.T) {
t.Setenv("BOLT_DB_PASSWORD", envCfg.Connection.Password)
t.Setenv("BOLT_DB_NAME", envCfg.Connection.DBName)
t.Setenv("BOLT_DB_DRIVER", envCfg.Connection.Driver)
+ t.Setenv("BOLT_DB_MIGRATIONS_TABLE", envCfg.Connection.MigrationsTable)
cfg, err := configloader.NewConfig()
assert.Nil(t, err)
@@ -119,6 +125,7 @@ func TestNewConfigSearchesParentDirectories(t *testing.T) {
bolttest.UnsetEnv(t, "BOLT_DB_PASSWORD")
bolttest.UnsetEnv(t, "BOLT_DB_NAME")
bolttest.UnsetEnv(t, "BOLT_DB_DRIVER")
+ bolttest.UnsetEnv(t, "BOLT_DB_MIGRATIONS_TABLE")
bolttest.UnsetEnv(t, "BOLT_MIGRATIONS_DIR_PATH")
bolttest.UnsetEnv(t, "BOLT_MIGRATIONS_VERSION_STYLE")
expectedCfg := configloader.Config{
@@ -126,6 +133,9 @@ func TestNewConfigSearchesParentDirectories(t *testing.T) {
DirectoryPath: "differentmigrationsdir",
VersionStyle: configloader.VersionStyleSequential,
},
+ Connection: configloader.ConnectionConfig{
+ MigrationsTable: "migration_table",
+ },
}
tmpdir := t.TempDir()
bolttest.CreateConfigFile(t, &expectedCfg, filepath.Join(tmpdir, "bolt.toml"))