INNER CODE UNIT · Go
TestLoadWithOptionalDefaults
rameshsunkara/go-rest-api-example · internal/config/config_test.go:34
func TestLoadWithOptionalDefaults(t *testing.T) {
// Set only required variables
t.Setenv("dbHosts", "localhost:27017")
t.Setenv("DBCredentialsSideCar", "/path/to/credentials")
// Clear optional variables to test defaults
t.Setenv("environment", "")
t.Setenv("port", "")
t.Setenv("logLevel", "")
t.Setenv("enableTracing", "")
t.Setenv("printDBQueries", "")
cfg, err := config.Load()
require.NoError(t, err)
assert.NotNil(t, cfg)
// Test that defaults are applied
assert.Equal(t, config.DefEnvironment, cfg.Environment)