X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=dmaap-mediator-producer%2Finternal%2Fconfig%2Fconfig_test.go;h=0fcbdd3f5c243de0d6dbd578fc79864faf41cf14;hb=b65d86fc9b02415e1adf2415f8c4a257378e9c09;hp=f0106d0f914cc707b8c540aa13eba3a39f3cfc1e;hpb=7ea5ec4f81f6e8c07b890f3d7567ce699c8d8d1d;p=nonrtric.git diff --git a/dmaap-mediator-producer/internal/config/config_test.go b/dmaap-mediator-producer/internal/config/config_test.go index f0106d0f..0fcbdd3f 100644 --- a/dmaap-mediator-producer/internal/config/config_test.go +++ b/dmaap-mediator-producer/internal/config/config_test.go @@ -21,31 +21,71 @@ package config import ( + "bytes" "os" "reflect" "testing" + + log "github.com/sirupsen/logrus" + "github.com/stretchr/testify/require" ) func TestNew_envVarsSetConfigContainSetValues(t *testing.T) { os.Setenv("LOG_LEVEL", "Debug") - os.Setenv("JOB_RESULT_URI", "testUrl") - os.Setenv("INFO_COORD_ADDR", "testAddr") - defer os.Clearenv() + os.Setenv("INFO_PRODUCER_HOST", "producerHost") + os.Setenv("INFO_PRODUCER_PORT", "8095") + os.Setenv("INFO_COORD_ADDR", "infoCoordAddr") + os.Setenv("MR_HOST", "mrHost") + os.Setenv("MR_PORT", "3908") + t.Cleanup(func() { + os.Clearenv() + }) wantConfig := Config{ LogLevel: "Debug", - JobResultUri: "testUrl", - InfoCoordinatorAddress: "testAddr", + InfoProducerHost: "producerHost", + InfoProducerPort: 8095, + InfoCoordinatorAddress: "infoCoordAddr", + MRHost: "mrHost", + MRPort: 3908, + } + if got := New(); !reflect.DeepEqual(got, &wantConfig) { + t.Errorf("New() = %v, want %v", got, &wantConfig) + } +} + +func TestNew_faultyIntValueSetConfigContainDefaultValueAndWarnInLog(t *testing.T) { + assertions := require.New(t) + var buf bytes.Buffer + log.SetOutput(&buf) + + os.Setenv("INFO_PRODUCER_PORT", "wrong") + t.Cleanup(func() { + log.SetOutput(os.Stderr) + os.Clearenv() + }) + wantConfig := Config{ + LogLevel: "Info", + InfoProducerHost: "", + InfoProducerPort: 8085, + InfoCoordinatorAddress: "http://enrichmentservice:8083", + MRHost: "http://message-router.onap", + MRPort: 3904, } if got := New(); !reflect.DeepEqual(got, &wantConfig) { t.Errorf("New() = %v, want %v", got, &wantConfig) } + logString := buf.String() + assertions.Contains(logString, "Invalid int value: wrong for variable: INFO_PRODUCER_PORT. Default value: 8085 will be used") } func TestNew_envVarsNotSetConfigContainDefaultValues(t *testing.T) { wantConfig := Config{ LogLevel: "Info", - JobResultUri: "", + InfoProducerHost: "", + InfoProducerPort: 8085, InfoCoordinatorAddress: "http://enrichmentservice:8083", + MRHost: "http://message-router.onap", + MRPort: 3904, } if got := New(); !reflect.DeepEqual(got, &wantConfig) { t.Errorf("New() = %v, want %v", got, &wantConfig)