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===================================
28 log "github.com/sirupsen/logrus"
29 "github.com/stretchr/testify/require"
32 func TestConfigurationValuesSetProperly(t *testing.T) {
34 assertions := require.New(t)
38 envVar map[string]string
45 name: "Test env variable contain correct set values",
48 ConsumerHost: "consumerHost",
50 SDNRAddress: "sdnrAddr",
53 InfoCoordinatorAddress: "infoCoordAddr",
54 LogLevel: log.InfoLevel,
59 name: "Test faulty int value is set for consumer port variable",
62 ConsumerHost: "consumerHost",
63 SDNRAddress: "sdnrAddr",
66 InfoCoordinatorAddress: "infoCoordAddr",
67 LogLevel: log.InfoLevel,
69 envVar: map[string]string{"CONSUMER_PORT": "wrong"},
73 name: "Test log level is wrongly set",
76 ConsumerHost: "consumerHost",
78 SDNRAddress: "sdnrAddr",
81 InfoCoordinatorAddress: "infoCoordAddr",
82 LogLevel: log.InfoLevel,
84 envVar: map[string]string{"LOG_LEVEL": "wrong"},
89 for i, tt := range tests {
90 t.Run(tt.name, func(t *testing.T) {
91 os.Setenv("CONSUMER_HOST", "consumerHost")
92 os.Setenv("CONSUMER_PORT", "8095")
93 os.Setenv("SDNR_ADDR", "sdnrAddr")
94 os.Setenv("SDNR_USER", "admin")
95 os.Setenv("SDNR_PASSWORD", "pass")
96 os.Setenv("INFO_COORD_ADDR", "infoCoordAddr")
98 for key, element := range tt.args.envVar {
99 os.Setenv(key, element)
105 log.SetOutput(os.Stderr)
110 assertions.Equal(&tt.args.conf, got)
112 logString := buf.String()
114 assertions.Contains(logString, "Invalid int value: wrong for variable: CONSUMER_PORT. Default value: 0 will be used")
117 assertions.Contains(logString, "Invalid log level: wrong. Log level will be Info!")