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,
56 JobId: "14e7bb84-a44d-44c1-90b7-6995a92ad83d",
61 name: "Test faulty int value is set for consumer port variable",
64 ConsumerHost: "consumerHost",
65 SDNRAddress: "sdnrAddr",
68 InfoCoordinatorAddress: "infoCoordAddr",
69 LogLevel: log.InfoLevel,
71 JobId: "14e7bb84-a44d-44c1-90b7-6995a92ad83d",
73 envVar: map[string]string{"CONSUMER_PORT": "wrong"},
77 name: "Test log level is wrongly set",
80 ConsumerHost: "consumerHost",
82 SDNRAddress: "sdnrAddr",
85 InfoCoordinatorAddress: "infoCoordAddr",
86 LogLevel: log.InfoLevel,
88 JobId: "14e7bb84-a44d-44c1-90b7-6995a92ad83d",
90 envVar: map[string]string{"LOG_LEVEL": "wrong"},
95 for i, tt := range tests {
96 t.Run(tt.name, func(t *testing.T) {
97 os.Setenv("CONSUMER_HOST", "consumerHost")
98 os.Setenv("CONSUMER_PORT", "8095")
99 os.Setenv("SDNR_ADDR", "sdnrAddr")
100 os.Setenv("SDNR_USER", "admin")
101 os.Setenv("SDNR_PASSWORD", "pass")
102 os.Setenv("INFO_COORD_ADDR", "infoCoordAddr")
103 os.Setenv("NODE_ID", "O-DU-1122")
104 os.Setenv("JOB_ID", "14e7bb84-a44d-44c1-90b7-6995a92ad83d")
106 for key, element := range tt.args.envVar {
107 os.Setenv(key, element)
113 log.SetOutput(os.Stderr)
118 assertions.Equal(&tt.args.conf, got)
120 logString := buf.String()
122 assertions.Contains(logString, "Invalid int value: wrong for variable: CONSUMER_PORT. Default value: 0 will be used")
125 assertions.Contains(logString, "Invalid log level: wrong. Log level will be Info!")