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 os.Setenv("LOG_LEVEL", "Debug")
35 os.Setenv("INFO_PRODUCER_SUPERVISION_CALLBACK_HOST", "supervisionCallbackHost")
36 os.Setenv("INFO_PRODUCER_SUPERVISION_CALLBACK_PORT", "8095")
37 os.Setenv("INFO_JOB_CALLBACK_HOST", "jobCallbackHost")
38 os.Setenv("INFO_JOB_CALLBACK_PORT", "8096")
39 os.Setenv("INFO_COORD_ADDR", "infoCoordAddr")
45 InfoProducerSupervisionCallbackHost: "supervisionCallbackHost",
46 InfoProducerSupervisionCallbackPort: 8095,
47 InfoJobCallbackHost: "jobCallbackHost",
48 InfoJobCallbackPort: 8096,
49 InfoCoordinatorAddress: "infoCoordAddr",
51 if got := New(); !reflect.DeepEqual(got, &wantConfig) {
52 t.Errorf("New() = %v, want %v", got, &wantConfig)
56 func TestNew_faultyIntValueSetConfigContainDefaultValueAndWarnInLog(t *testing.T) {
57 assertions := require.New(t)
61 os.Setenv("INFO_PRODUCER_SUPERVISION_CALLBACK_PORT", "wrong")
63 log.SetOutput(os.Stderr)
68 InfoProducerSupervisionCallbackHost: "",
69 InfoProducerSupervisionCallbackPort: 8085,
70 InfoJobCallbackHost: "",
71 InfoJobCallbackPort: 8086,
72 InfoCoordinatorAddress: "http://enrichmentservice:8083",
74 if got := New(); !reflect.DeepEqual(got, &wantConfig) {
75 t.Errorf("New() = %v, want %v", got, &wantConfig)
77 logString := buf.String()
78 assertions.Contains(logString, "Invalid int value: wrong for variable: INFO_PRODUCER_SUPERVISION_CALLBACK_PORT. Default value: 8085 will be used")
81 func TestNew_envVarsNotSetConfigContainDefaultValues(t *testing.T) {
84 InfoProducerSupervisionCallbackHost: "",
85 InfoProducerSupervisionCallbackPort: 8085,
86 InfoJobCallbackHost: "",
87 InfoJobCallbackPort: 8086,
88 InfoCoordinatorAddress: "http://enrichmentservice:8083",
90 if got := New(); !reflect.DeepEqual(got, &wantConfig) {
91 t.Errorf("New() = %v, want %v", got, &wantConfig)