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("DMAAP_MR_ADDR", "mrHost:3908")
40 os.Setenv("PRODUCER_CERT_PATH", "cert")
41 os.Setenv("PRODUCER_KEY_PATH", "key")
46 LogLevel: log.DebugLevel,
47 InfoProducerHost: "producerHost",
48 InfoProducerPort: 8095,
49 InfoCoordinatorAddress: "infoCoordAddr",
50 DMaaPMRAddress: "mrHost:3908",
51 ProducerCertPath: "cert",
52 ProducerKeyPath: "key",
56 assertions.Equal(&wantConfig, got)
59 func TestNew_faultyIntValueSetConfigContainDefaultValueAndWarnInLog(t *testing.T) {
60 assertions := require.New(t)
64 os.Setenv("INFO_PRODUCER_PORT", "wrong")
66 log.SetOutput(os.Stderr)
70 LogLevel: log.InfoLevel,
72 InfoProducerPort: 8085,
73 InfoCoordinatorAddress: "https://enrichmentservice:8434",
74 DMaaPMRAddress: "https://message-router.onap:3905",
75 ProducerCertPath: "configs/producer.crt",
76 ProducerKeyPath: "configs/producer.key",
78 if got := New(); !reflect.DeepEqual(got, &wantConfig) {
79 t.Errorf("New() = %v, want %v", got, &wantConfig)
81 logString := buf.String()
82 assertions.Contains(logString, "Invalid int value: wrong for variable: INFO_PRODUCER_PORT. Default value: 8085 will be used")
85 func TestNew_envFaultyLogLevelConfigContainDefaultValues(t *testing.T) {
86 assertions := require.New(t)
90 os.Setenv("LOG_LEVEL", "wrong")
92 log.SetOutput(os.Stderr)
97 LogLevel: log.InfoLevel,
99 InfoProducerPort: 8085,
100 InfoCoordinatorAddress: "https://enrichmentservice:8434",
101 DMaaPMRAddress: "https://message-router.onap:3905",
102 ProducerCertPath: "configs/producer.crt",
103 ProducerKeyPath: "configs/producer.key",
108 assertions.Equal(&wantConfig, got)
109 logString := buf.String()
110 assertions.Contains(logString, "Invalid log level: wrong. Log level will be Info!")