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===================================
28 log "github.com/sirupsen/logrus"
29 "github.com/stretchr/testify/require"
32 func TestNew_envVarsSetConfigContainSetValues(t *testing.T) {
33 assertions := require.New(t)
34 os.Setenv("LOG_LEVEL", "Debug")
35 os.Setenv("CONSUMER_HOST", "consumerHost")
36 os.Setenv("CONSUMER_PORT", "8095")
37 os.Setenv("INFO_COORD_ADDR", "infoCoordAddr")
38 os.Setenv("SDNR_HOST", "sdnrHost")
39 os.Setenv("SDNR_PORT", "3908")
40 os.Setenv("SDNR_USER", "admin")
41 os.Setenv("SDNR_PASSWORD", "pwd")
42 os.Setenv("ORU_TO_ODU_MAP_FILE", "file")
47 LogLevel: log.DebugLevel,
48 ConsumerHost: "consumerHost",
50 InfoCoordinatorAddress: "infoCoordAddr",
55 ORUToODUMapFile: "file",
59 assertions.Equal(&wantConfig, got)
62 func TestNew_faultyIntValueSetConfigContainDefaultValueAndWarnInLog(t *testing.T) {
63 assertions := require.New(t)
67 os.Setenv("CONSUMER_PORT", "wrong")
69 log.SetOutput(os.Stderr)
73 LogLevel: log.InfoLevel,
76 InfoCoordinatorAddress: "http://enrichmentservice:8083",
77 SDNRHost: "http://localhost",
80 SDNPassword: "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U",
81 ORUToODUMapFile: "o-ru-to-o-du-map.csv",
85 assertions.Equal(&wantConfig, got)
87 logString := buf.String()
88 assertions.Contains(logString, "Invalid int value: wrong for variable: CONSUMER_PORT. Default value: 0 will be used")
91 func TestNew_envFaultyLogLevelConfigContainDefaultValues(t *testing.T) {
92 assertions := require.New(t)
96 os.Setenv("LOG_LEVEL", "wrong")
98 log.SetOutput(os.Stderr)
101 wantConfig := Config{
102 LogLevel: log.InfoLevel,
105 InfoCoordinatorAddress: "http://enrichmentservice:8083",
106 SDNRHost: "http://localhost",
109 SDNPassword: "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U",
110 ORUToODUMapFile: "o-ru-to-o-du-map.csv",
113 assertions.Equal(&wantConfig, got)
114 logString := buf.String()
115 assertions.Contains(logString, "Invalid log level: wrong. Log level will be Info!")