diff --git a/README.md b/README.md index ce2d75ef4aa0302c43c54cedbcf027b9e42396a9..42b5fb5b64ccd7e2e53fe8e09d75a17adfd0fe9a 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,6 @@ buf generate ACTIVE_PROFILE=local go run cmd/antragsraum-proxy/main.go ``` - - ## Config config.yml is the default config for deployment @@ -71,8 +69,6 @@ logging: level: "ERROR" | "WARN" | "INFO" | "DEBUG" ``` - - ### Releasing Diese Schritte ausführen: @@ -91,4 +87,3 @@ Diese Schritte ausführen: * Release-Branch in den Master mergen nicht pushen! * Die Version von 'var version' in cmd/antragraum-proxy/main.go "vX.X.X" auf "vX.X.X-beta.x" ändern * Master Branch pushen - diff --git a/internal/config/config.go b/internal/config/config.go index a21874c0e82210db33e4027512f8a297b33d8215..8a668af900963f92a2a1131a9bee4c4f138dce5d 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -26,17 +26,17 @@ package config import ( + "fmt" "gopkg.in/yaml.v3" "log" "os" "testing" - "fmt" ) const ( - defaultConfig = "config.yml" - testFilePath = "testdata/" - activeProfile = "ACTIVE_PROFILE" + defaultConfig = "config.yml" + testFilePath = "testdata/" + activeProfileParam = "ACTIVE_PROFILE" ) type Config struct { @@ -63,18 +63,18 @@ func LoadConfig(configFilePath ...string) Config { var config Config configFile := defaultConfig - - env := os.Getenv(activeProfile) + + env := os.Getenv(activeProfileParam) if env != "" { configFile = fmt.Sprintf("config-%s.yml", env) } fp := fmt.Sprintf("config/%s", configFile) - + if len(configFilePath) > 0 { fp = configFilePath[0] } else if testing.Testing() { - fp = testFilePath+configFile + fp = testFilePath + configFile } file, err := os.ReadFile(fp) diff --git a/internal/config/config_test.go b/internal/config/config_test.go index f0877298897399ec976229c3adc3e8ab371a27b9..613e517c1a4aff212aeb7b842efd64196af553e5 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -26,9 +26,9 @@ package config import ( - "testing" "github.com/stretchr/testify/assert" "os" + "testing" ) func TestLoadConfig(t *testing.T) { @@ -46,12 +46,12 @@ func TestLoadConfig(t *testing.T) { }) t.Run("should load local config", func(t *testing.T) { - assert.NoError(t, os.Setenv(activeProfile, "local"), "Setenv "+activeProfile+" should not return an error") + assert.NoError(t, os.Setenv(activeProfileParam, "local"), "Setenv "+activeProfileParam+" should not return an error") config := LoadConfig() - assert.NoError(t, os.Unsetenv(activeProfile), "Unsetenv "+activeProfile+" should not return an error") - + assert.NoError(t, os.Unsetenv(activeProfileParam), "Unsetenv "+activeProfileParam+" should not return an error") + expectedConfig := Config{} expectedConfig.Grpc.Server.Mock = true expectedConfig.Http.Server.Port = 8082 @@ -61,5 +61,4 @@ func TestLoadConfig(t *testing.T) { assert.Equal(t, expectedConfig, config) }) - }