X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=auth-token-fetch%2Fconfig_test.go;h=0dd1d3590af6aa9836e82b4c92e3ee0501da0a81;hb=HEAD;hp=8b441c145ba6590e6f58cf61c47b240df863eb2e;hpb=0d129fcb9c18a4fdc989a4c338d8407fea76ee97;p=nonrtric.git diff --git a/auth-token-fetch/config_test.go b/auth-token-fetch/config_test.go index 8b441c14..0dd1d359 100644 --- a/auth-token-fetch/config_test.go +++ b/auth-token-fetch/config_test.go @@ -39,6 +39,7 @@ func TestNew_envVarsSetConfigContainSetValues(t *testing.T) { os.Setenv("OUTPUT_FILE", "OUTPUT_FILE") os.Setenv("AUTH_SERVICE_URL", "AUTH_SERVICE_URL") os.Setenv("REFRESH_MARGIN_SECONDS", "33") + os.Setenv("ROOT_CA_CERTS_PATH", "ROOT_CA_CERTS_PATH") t.Cleanup(func() { os.Clearenv() @@ -52,9 +53,46 @@ func TestNew_envVarsSetConfigContainSetValues(t *testing.T) { ClientSecret: "CREDS_CLIENT_SECRET", ClientId: "CREDS_CLIENT_ID", AuthTokenOutputFileName: "OUTPUT_FILE", + CACertsPath: "ROOT_CA_CERTS_PATH", RefreshMarginSeconds: 33, } got := NewConfig() + assertions.Equal(nil, validateConfiguration(got)) assertions.Equal(&wantConfig, got) } + +func TestNew_defaultValues(t *testing.T) { + assertions := require.New(t) + + wantConfig := Config{ + LogLevel: log.InfoLevel, + CertPath: "security/tls.crt", + KeyPath: "security/tls.key", + AuthServiceUrl: "https://localhost:39687/example-singlelogin-sever/login", + GrantType: "", + ClientSecret: "", + ClientId: "", + AuthTokenOutputFileName: "/tmp/authToken.txt", + CACertsPath: "", + RefreshMarginSeconds: 5, + } + got := NewConfig() + assertions.Equal(nil, validateConfiguration(got)) + + assertions.Equal(&wantConfig, got) +} + +func TestNew_invalidValues(t *testing.T) { + assertions := require.New(t) + + os.Setenv("LOG_LEVEL", "Junk") + os.Setenv("REFRESH_MARGIN_SECONDS", "Junk") + t.Cleanup(func() { + os.Clearenv() + }) + + got := NewConfig() + assertions.Equal(log.InfoLevel, got.LogLevel) + assertions.Equal(5, got.RefreshMarginSeconds) +}