2 // ========================LICENSE_START=================================
5 // Copyright (C) 2022: Nordix Foundation
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 // ========================LICENSE_END===================================
27 log "github.com/sirupsen/logrus"
28 "github.com/stretchr/testify/require"
31 func TestNew_envVarsSetConfigContainSetValues(t *testing.T) {
32 assertions := require.New(t)
33 os.Setenv("LOG_LEVEL", "Debug")
34 os.Setenv("CERT_PATH", "CERT_PATH")
35 os.Setenv("CERT_KEY_PATH", "CERT_KEY_PATH")
36 os.Setenv("CREDS_GRANT_TYPE", "CREDS_GRANT_TYPE")
37 os.Setenv("CREDS_CLIENT_SECRET", "CREDS_CLIENT_SECRET")
38 os.Setenv("CREDS_CLIENT_ID", "CREDS_CLIENT_ID")
39 os.Setenv("OUTPUT_FILE", "OUTPUT_FILE")
40 os.Setenv("AUTH_SERVICE_URL", "AUTH_SERVICE_URL")
41 os.Setenv("REFRESH_MARGIN_SECONDS", "33")
42 os.Setenv("ROOT_CA_CERTS_PATH", "ROOT_CA_CERTS_PATH")
48 LogLevel: log.DebugLevel,
49 CertPath: "CERT_PATH",
50 KeyPath: "CERT_KEY_PATH",
51 AuthServiceUrl: "AUTH_SERVICE_URL",
52 GrantType: "CREDS_GRANT_TYPE",
53 ClientSecret: "CREDS_CLIENT_SECRET",
54 ClientId: "CREDS_CLIENT_ID",
55 AuthTokenOutputFileName: "OUTPUT_FILE",
56 CACertsPath: "ROOT_CA_CERTS_PATH",
57 RefreshMarginSeconds: 33,
60 assertions.Equal(nil, validateConfiguration(got))
62 assertions.Equal(&wantConfig, got)
65 func TestNew_defaultValues(t *testing.T) {
66 assertions := require.New(t)
69 LogLevel: log.InfoLevel,
70 CertPath: "security/tls.crt",
71 KeyPath: "security/tls.key",
72 AuthServiceUrl: "https://localhost:39687/example-singlelogin-sever/login",
76 AuthTokenOutputFileName: "/tmp/authToken.txt",
78 RefreshMarginSeconds: 5,
81 assertions.Equal(nil, validateConfiguration(got))
83 assertions.Equal(&wantConfig, got)
86 func TestNew_invalidValues(t *testing.T) {
87 assertions := require.New(t)
89 os.Setenv("LOG_LEVEL", "Junk")
90 os.Setenv("REFRESH_MARGIN_SECONDS", "Junk")
96 assertions.Equal(log.InfoLevel, got.LogLevel)
97 assertions.Equal(5, got.RefreshMarginSeconds)