aboutsummaryrefslogtreecommitdiffstats
path: root/internal/configloader/configloader_test.go
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2024-03-09 12:07:30 -0500
committerEugene Triguba <eugenetriguba@gmail.com>2024-03-09 12:07:30 -0500
commit18cbade269362a3fed5763e2b1b39be33ba56aaf (patch)
treed31df309169381b83f9cad67da15f38d0b3cccc6 /internal/configloader/configloader_test.go
parentAdd mysql docker compose file and use matrix in workflow (diff)
downloadcli-18cbade269362a3fed5763e2b1b39be33ba56aaf.zip
Fix tests to work without Dockerfile.test
Diffstat (limited to 'internal/configloader/configloader_test.go')
-rw-r--r--internal/configloader/configloader_test.go42
1 files changed, 41 insertions, 1 deletions
diff --git a/internal/configloader/configloader_test.go b/internal/configloader/configloader_test.go
index 0ad6930..6aa3b45 100644
--- a/internal/configloader/configloader_test.go
+++ b/internal/configloader/configloader_test.go
@@ -3,6 +3,7 @@ package configloader_test
import (
"fmt"
"os"
+ "path/filepath"
"testing"
"github.com/eugenetriguba/bolt/internal/bolttest"
@@ -35,6 +36,14 @@ func TestNewConfigWithInvalidVersionStyle(t *testing.T) {
}
func TestNewConfigFindsFileAndPopulatesConfigStruct(t *testing.T) {
+ bolttest.UnsetEnv(t, "BOLT_DB_CONN_HOST")
+ bolttest.UnsetEnv(t, "BOLT_DB_CONN_PORT")
+ bolttest.UnsetEnv(t, "BOLT_DB_CONN_USER")
+ bolttest.UnsetEnv(t, "BOLT_DB_CONN_PASSWORD")
+ bolttest.UnsetEnv(t, "BOLT_DB_CONN_DBNAME")
+ bolttest.UnsetEnv(t, "BOLT_DB_CONN_DRIVER")
+ bolttest.UnsetEnv(t, "BOLT_MIGRATIONS_DIR_PATH")
+ bolttest.UnsetEnv(t, "BOLT_MIGRATIONS_VERSION_STYLE")
expectedCfg := configloader.Config{
Migrations: configloader.MigrationsConfig{
DirectoryPath: "myfancymigrations",
@@ -49,9 +58,12 @@ func TestNewConfigFindsFileAndPopulatesConfigStruct(t *testing.T) {
Driver: "postgres",
},
}
- bolttest.CreateConfigFile(t, &expectedCfg, "bolt.toml")
+ tmpdir := t.TempDir()
+ bolttest.ChangeCwd(t, tmpdir)
+ bolttest.CreateConfigFile(t, &expectedCfg, filepath.Join(tmpdir, "bolt.toml"))
cfg, err := configloader.NewConfig()
+
assert.Nil(t, err)
assert.DeepEqual(t, *cfg, expectedCfg)
}
@@ -100,3 +112,31 @@ func TestNewConfigCanBeOverridenByEnvVars(t *testing.T) {
assert.Nil(t, err)
assert.DeepEqual(t, *cfg, envCfg)
}
+
+func TestNewConfigSearchesParentDirectories(t *testing.T) {
+ bolttest.UnsetEnv(t, "BOLT_DB_CONN_HOST")
+ bolttest.UnsetEnv(t, "BOLT_DB_CONN_PORT")
+ bolttest.UnsetEnv(t, "BOLT_DB_CONN_USER")
+ bolttest.UnsetEnv(t, "BOLT_DB_CONN_PASSWORD")
+ bolttest.UnsetEnv(t, "BOLT_DB_CONN_DBNAME")
+ bolttest.UnsetEnv(t, "BOLT_DB_CONN_DRIVER")
+ bolttest.UnsetEnv(t, "BOLT_MIGRATIONS_DIR_PATH")
+ bolttest.UnsetEnv(t, "BOLT_MIGRATIONS_VERSION_STYLE")
+ expectedCfg := configloader.Config{
+ Migrations: configloader.MigrationsConfig{
+ DirectoryPath: "differentmigrationsdir",
+ VersionStyle: configloader.VersionStyleSequential,
+ },
+ }
+ tmpdir := t.TempDir()
+ bolttest.CreateConfigFile(t, &expectedCfg, filepath.Join(tmpdir, "bolt.toml"))
+ nestedTmpDir := filepath.Join(tmpdir, "nested-dir", "nested-x2-dir")
+ err := os.MkdirAll(nestedTmpDir, 0755)
+ assert.Nil(t, err)
+ bolttest.ChangeCwd(t, nestedTmpDir)
+
+ cfg, err := configloader.NewConfig()
+ assert.Nil(t, err)
+
+ assert.DeepEqual(t, *cfg, expectedCfg)
+}