diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2025-07-23 21:39:11 -0400 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2025-07-23 21:39:11 -0400 |
| commit | 5264264333f211c9d40108955e167d28fa73f77d (patch) | |
| tree | 6801a3d0460360bff5bc0b76ac482fa774e97043 /internal/configloader/configloader_test.go | |
| parent | Fix contributing link (diff) | |
| download | cli-5264264333f211c9d40108955e167d28fa73f77d.zip | |
Use DSN for handling connection parameters
Diffstat (limited to 'internal/configloader/configloader_test.go')
| -rw-r--r-- | internal/configloader/configloader_test.go | 37 |
1 files changed, 7 insertions, 30 deletions
diff --git a/internal/configloader/configloader_test.go b/internal/configloader/configloader_test.go index f988afb..ce738e6 100644 --- a/internal/configloader/configloader_test.go +++ b/internal/configloader/configloader_test.go @@ -36,26 +36,19 @@ func TestNewConfigWithInvalidVersionStyle(t *testing.T) { } func TestNewConfigFindsFileAndPopulatesConfigStruct(t *testing.T) { - bolttest.UnsetEnv(t, "BOLT_DB_HOST") - bolttest.UnsetEnv(t, "BOLT_DB_PORT") - bolttest.UnsetEnv(t, "BOLT_DB_USER") - bolttest.UnsetEnv(t, "BOLT_DB_PASSWORD") - bolttest.UnsetEnv(t, "BOLT_DB_NAME") + bolttest.UnsetEnv(t, "BOLT_DB_DSN") 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{ Migrations: configloader.MigrationsConfig{ DirectoryPath: "myfancymigrations", VersionStyle: configloader.VersionStyleSequential, }, Connection: configloader.ConnectionConfig{ - Host: "testhost", - Port: "1234", - User: "testuser", - Password: "testpassword", - DBName: "testdb", + DSN: "postgresql://testuser:testpassword@testhost:1234/testdb", Driver: "postgresql", MigrationsTable: "test_table", }, @@ -77,11 +70,7 @@ func TestNewConfigCanBeOverridenByEnvVars(t *testing.T) { VersionStyle: configloader.VersionStyleSequential, }, Connection: configloader.ConnectionConfig{ - Host: "testhost", - Port: "1234", - User: "testuser", - Password: "testpassword", - DBName: "testdb", + DSN: "mysql://testuser:testpassword@testhost:1234/testdb", Driver: "mysql", MigrationsTable: "test_table", }, @@ -94,22 +83,14 @@ func TestNewConfigCanBeOverridenByEnvVars(t *testing.T) { VersionStyle: configloader.VersionStyleTimestamp, }, Connection: configloader.ConnectionConfig{ - Host: "envtesthost", - Port: "4321", - User: "envtestuser", - Password: "envtestpassword", - DBName: "envtestdb", + DSN: "postgresql://envtestuser:envtestpassword@envtesthost:4321/envtestdb", Driver: "postgresql", MigrationsTable: "different_table", }, } t.Setenv("BOLT_MIGRATIONS_VERSION_STYLE", string(envCfg.Migrations.VersionStyle)) t.Setenv("BOLT_MIGRATIONS_DIR_PATH", envCfg.Migrations.DirectoryPath) - t.Setenv("BOLT_DB_HOST", envCfg.Connection.Host) - t.Setenv("BOLT_DB_PORT", envCfg.Connection.Port) - t.Setenv("BOLT_DB_USER", envCfg.Connection.User) - t.Setenv("BOLT_DB_PASSWORD", envCfg.Connection.Password) - t.Setenv("BOLT_DB_NAME", envCfg.Connection.DBName) + t.Setenv("BOLT_DB_DSN", envCfg.Connection.DSN) t.Setenv("BOLT_DB_DRIVER", envCfg.Connection.Driver) t.Setenv("BOLT_DB_MIGRATIONS_TABLE", envCfg.Connection.MigrationsTable) @@ -119,11 +100,7 @@ func TestNewConfigCanBeOverridenByEnvVars(t *testing.T) { } func TestNewConfigSearchesParentDirectories(t *testing.T) { - bolttest.UnsetEnv(t, "BOLT_DB_HOST") - bolttest.UnsetEnv(t, "BOLT_DB_PORT") - bolttest.UnsetEnv(t, "BOLT_DB_USER") - bolttest.UnsetEnv(t, "BOLT_DB_PASSWORD") - bolttest.UnsetEnv(t, "BOLT_DB_NAME") + bolttest.UnsetEnv(t, "BOLT_DB_DSN") bolttest.UnsetEnv(t, "BOLT_DB_DRIVER") bolttest.UnsetEnv(t, "BOLT_DB_MIGRATIONS_TABLE") bolttest.UnsetEnv(t, "BOLT_MIGRATIONS_DIR_PATH") |