2 // ========================LICENSE_START=================================
5 // Copyright (C) 2021: 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===================================
29 log "github.com/sirupsen/logrus"
30 "github.com/stretchr/testify/require"
33 func TestNew_envVarsSetConfigContainSetValues(t *testing.T) {
34 assertions := require.New(t)
35 os.Setenv("LOG_LEVEL", "Debug")
36 os.Setenv("INFO_PRODUCER_HOST", "producerHost")
37 os.Setenv("INFO_PRODUCER_PORT", "8095")
38 os.Setenv("INFO_COORD_ADDR", "infoCoordAddr")
39 os.Setenv("MR_HOST", "mrHost")
40 os.Setenv("MR_PORT", "3908")
45 LogLevel: log.DebugLevel,
46 InfoProducerHost: "producerHost",
47 InfoProducerPort: 8095,
48 InfoCoordinatorAddress: "infoCoordAddr",
54 assertions.Equal(&wantConfig, got)
57 func TestNew_faultyIntValueSetConfigContainDefaultValueAndWarnInLog(t *testing.T) {
58 assertions := require.New(t)
62 os.Setenv("INFO_PRODUCER_PORT", "wrong")
64 log.SetOutput(os.Stderr)
68 LogLevel: log.InfoLevel,
70 InfoProducerPort: 8085,
71 InfoCoordinatorAddress: "http://enrichmentservice:8083",
72 MRHost: "http://message-router.onap",
75 if got := New(); !reflect.DeepEqual(got, &wantConfig) {
76 t.Errorf("New() = %v, want %v", got, &wantConfig)
78 logString := buf.String()
79 assertions.Contains(logString, "Invalid int value: wrong for variable: INFO_PRODUCER_PORT. Default value: 8085 will be used")
82 func TestNew_envFaultyLogLevelConfigContainDefaultValues(t *testing.T) {
83 assertions := require.New(t)
87 os.Setenv("LOG_LEVEL", "wrong")
89 log.SetOutput(os.Stderr)
94 LogLevel: log.InfoLevel,
96 InfoProducerPort: 8085,
97 InfoCoordinatorAddress: "http://enrichmentservice:8083",
98 MRHost: "http://message-router.onap",
104 assertions.Equal(&wantConfig, got)
105 logString := buf.String()
106 assertions.Contains(logString, "Invalid log level: wrong. Log level will be Info!")