Merge "Use env varialbes to replace image urls & tags"
[nonrtric.git] / test / usecases / oruclosedlooprecovery / goversion / internal / config / config_test.go
index e278e60..3d9983a 100644 (file)
@@ -23,7 +23,6 @@ package config
 import (
        "bytes"
        "os"
-       "reflect"
        "testing"
 
        log "github.com/sirupsen/logrus"
@@ -31,32 +30,35 @@ import (
 )
 
 func TestNew_envVarsSetConfigContainSetValues(t *testing.T) {
-       os.Setenv("LOG_LEVEL", "Debug")
+       assertions := require.New(t)
        os.Setenv("CONSUMER_HOST", "consumerHost")
        os.Setenv("CONSUMER_PORT", "8095")
        os.Setenv("INFO_COORD_ADDR", "infoCoordAddr")
-       os.Setenv("SDNR_HOST", "sdnrHost")
-       os.Setenv("SDNR_PORT", "3908")
+       os.Setenv("SDNR_ADDR", "sdnrHost:3908")
        os.Setenv("SDNR_USER", "admin")
        os.Setenv("SDNR_PASSWORD", "pwd")
        os.Setenv("ORU_TO_ODU_MAP_FILE", "file")
+       os.Setenv("CONSUMER_CERT_PATH", "cert")
+       os.Setenv("CONSUMER_KEY_PATH", "key")
+       os.Setenv("LOG_LEVEL", "Debug")
        t.Cleanup(func() {
                os.Clearenv()
        })
        wantConfig := Config{
-               LogLevel:               log.DebugLevel,
                ConsumerHost:           "consumerHost",
                ConsumerPort:           8095,
                InfoCoordinatorAddress: "infoCoordAddr",
-               SDNRHost:               "sdnrHost",
-               SDNRPort:               3908,
+               SDNRAddress:            "sdnrHost:3908",
                SDNRUser:               "admin",
                SDNPassword:            "pwd",
                ORUToODUMapFile:        "file",
+               ConsumerCertPath:       "cert",
+               ConsumerKeyPath:        "key",
+               LogLevel:               log.DebugLevel,
        }
-       if got := New(); !reflect.DeepEqual(got, &wantConfig) {
-               t.Errorf("New() = %v, want %v", got, &wantConfig)
-       }
+
+       got := New()
+       assertions.Equal(&wantConfig, got)
 }
 
 func TestNew_faultyIntValueSetConfigContainDefaultValueAndWarnInLog(t *testing.T) {
@@ -70,19 +72,21 @@ func TestNew_faultyIntValueSetConfigContainDefaultValueAndWarnInLog(t *testing.T
                os.Clearenv()
        })
        wantConfig := Config{
-               LogLevel:               log.InfoLevel,
                ConsumerHost:           "",
                ConsumerPort:           0,
                InfoCoordinatorAddress: "http://enrichmentservice:8083",
-               SDNRHost:               "http://localhost",
-               SDNRPort:               3904,
+               SDNRAddress:            "http://localhost:3904",
                SDNRUser:               "admin",
                SDNPassword:            "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U",
                ORUToODUMapFile:        "o-ru-to-o-du-map.csv",
+               ConsumerCertPath:       "security/consumer.crt",
+               ConsumerKeyPath:        "security/consumer.key",
+               LogLevel:               log.InfoLevel,
        }
-       if got := New(); !reflect.DeepEqual(got, &wantConfig) {
-               t.Errorf("New() = %v, want %v", got, &wantConfig)
-       }
+
+       got := New()
+       assertions.Equal(&wantConfig, got)
+
        logString := buf.String()
        assertions.Contains(logString, "Invalid int value: wrong for variable: CONSUMER_PORT. Default value: 0 will be used")
 }
@@ -98,22 +102,19 @@ func TestNew_envFaultyLogLevelConfigContainDefaultValues(t *testing.T) {
                os.Clearenv()
        })
        wantConfig := Config{
-               LogLevel:               log.InfoLevel,
                ConsumerHost:           "",
                ConsumerPort:           0,
                InfoCoordinatorAddress: "http://enrichmentservice:8083",
-               SDNRHost:               "http://localhost",
-               SDNRPort:               3904,
+               SDNRAddress:            "http://localhost:3904",
                SDNRUser:               "admin",
                SDNPassword:            "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U",
                ORUToODUMapFile:        "o-ru-to-o-du-map.csv",
+               ConsumerCertPath:       "security/consumer.crt",
+               ConsumerKeyPath:        "security/consumer.key",
+               LogLevel:               log.InfoLevel,
        }
-       if got := New(); !reflect.DeepEqual(got, &wantConfig) {
-               t.Errorf("New() = %v, want %v", got, &wantConfig)
-       }
-       if got := New(); !reflect.DeepEqual(got, &wantConfig) {
-               t.Errorf("New() = %v, want %v", got, &wantConfig)
-       }
+       got := New()
+       assertions.Equal(&wantConfig, got)
        logString := buf.String()
        assertions.Contains(logString, "Invalid log level: wrong. Log level will be Info!")
 }