From 3e1d5ed56dd622043eda7559a415792d97c6ddd5 Mon Sep 17 00:00:00 2001 From: Tomas Dvorak Date: Fri, 18 Sep 2026 21:50:27 +0200 Subject: [PATCH] test(conf): cover CR_CONF_Database.Name env override (#3327) The env-override rework in d00f447 fixed Section.Key parsing; lock the behavior in with a regression test so dbname cannot silently fall back to the username again. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- pkg/conf/conf_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 pkg/conf/conf_test.go diff --git a/pkg/conf/conf_test.go b/pkg/conf/conf_test.go new file mode 100644 index 00000000..7786e682 --- /dev/null +++ b/pkg/conf/conf_test.go @@ -0,0 +1,27 @@ +package conf + +import ( + "os" + "path/filepath" + "testing" + + "github.com/cloudreve/Cloudreve/v4/pkg/logging" + "github.com/stretchr/testify/require" +) + +func TestEnvOverrideDatabaseName(t *testing.T) { + dir := t.TempDir() + confPath := filepath.Join(dir, "conf.ini") + require.NoError(t, os.WriteFile(confPath, []byte("[System]\nDebug = false\nMode = master\nListen = :5212\nSessionSecret = s\nHashIDSalt = s\n"), 0644)) + + t.Setenv("CR_CONF_Database.Type", "postgres") + t.Setenv("CR_CONF_Database.Host", "postgresql") + t.Setenv("CR_CONF_Database.User", "user") + t.Setenv("CR_CONF_Database.Name", "database") + t.Setenv("CR_CONF_Database.Port", "5432") + + p, err := NewIniConfigProvider(confPath, logging.NewConsoleLogger(logging.LevelDebug)) + require.NoError(t, err) + require.Equal(t, "user", p.Database().User) + require.Equal(t, "database", p.Database().Name) +}