X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=test%2Fusecases%2Foruclosedlooprecovery%2Fgoversion%2Finternal%2Fconfig%2Fconfig_test.go;h=3d9983a63742b364351a037fb680c9e1201a5ad8;hb=46a0fd717e5f49ebae6cb2c4fbcf54f0e329dc86;hp=e278e60c34bed3bc4e4ca8a215dd665493922bd6;hpb=2f0d0d08efe5efe671178e63fdab4dacee543f9a;p=nonrtric.git diff --git a/test/usecases/oruclosedlooprecovery/goversion/internal/config/config_test.go b/test/usecases/oruclosedlooprecovery/goversion/internal/config/config_test.go index e278e60c..3d9983a6 100644 --- a/test/usecases/oruclosedlooprecovery/goversion/internal/config/config_test.go +++ b/test/usecases/oruclosedlooprecovery/goversion/internal/config/config_test.go @@ -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!") }