Merge "Change of ECS to ICS in test env"
[nonrtric.git] / dmaap-mediator-producer / internal / config / config_test.go
index fc64e57..faf5900 100644 (file)
@@ -23,7 +23,7 @@ package config
 import (
        "bytes"
        "os"
-       "reflect"
+       "path/filepath"
        "testing"
 
        log "github.com/sirupsen/logrus"
@@ -36,8 +36,9 @@ func TestNew_envVarsSetConfigContainSetValues(t *testing.T) {
        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")
+       os.Setenv("DMAAP_MR_ADDR", "mrHost:3908")
+       os.Setenv("PRODUCER_CERT_PATH", "cert")
+       os.Setenv("PRODUCER_KEY_PATH", "key")
        t.Cleanup(func() {
                os.Clearenv()
        })
@@ -46,8 +47,9 @@ func TestNew_envVarsSetConfigContainSetValues(t *testing.T) {
                InfoProducerHost:       "producerHost",
                InfoProducerPort:       8095,
                InfoCoordinatorAddress: "infoCoordAddr",
-               MRHost:                 "mrHost",
-               MRPort:                 3908,
+               DMaaPMRAddress:         "mrHost:3908",
+               ProducerCertPath:       "cert",
+               ProducerKeyPath:        "key",
        }
        got := New()
 
@@ -68,13 +70,13 @@ func TestNew_faultyIntValueSetConfigContainDefaultValueAndWarnInLog(t *testing.T
                LogLevel:               log.InfoLevel,
                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)
+               InfoCoordinatorAddress: "https://informationservice:8434",
+               DMaaPMRAddress:         "https://message-router.onap:3905",
+               ProducerCertPath:       "security/producer.crt",
+               ProducerKeyPath:        "security/producer.key",
        }
+       got := New()
+       assertions.Equal(&wantConfig, got)
        logString := buf.String()
        assertions.Contains(logString, "Invalid int value: wrong for variable: INFO_PRODUCER_PORT. Default value: 8085 will be used")
 }
@@ -94,9 +96,10 @@ func TestNew_envFaultyLogLevelConfigContainDefaultValues(t *testing.T) {
                LogLevel:               log.InfoLevel,
                InfoProducerHost:       "",
                InfoProducerPort:       8085,
-               InfoCoordinatorAddress: "http://enrichmentservice:8083",
-               MRHost:                 "http://message-router.onap",
-               MRPort:                 3904,
+               InfoCoordinatorAddress: "https://informationservice:8434",
+               DMaaPMRAddress:         "https://message-router.onap:3905",
+               ProducerCertPath:       "security/producer.crt",
+               ProducerKeyPath:        "security/producer.key",
        }
 
        got := New()
@@ -105,3 +108,30 @@ func TestNew_envFaultyLogLevelConfigContainDefaultValues(t *testing.T) {
        logString := buf.String()
        assertions.Contains(logString, "Invalid log level: wrong. Log level will be Info!")
 }
+
+const typeDefinition = `{"types": [{"id": "type1", "dmaapTopicUrl": "events/unauthenticated.SEC_FAULT_OUTPUT/dmaapmediatorproducer/type1"}]}`
+
+func TestGetTypesFromConfiguration_fileOkShouldReturnSliceOfTypeDefinitions(t *testing.T) {
+       assertions := require.New(t)
+       typesDir, err := os.MkdirTemp("", "configs")
+       if err != nil {
+               t.Errorf("Unable to create temporary directory for types due to: %v", err)
+       }
+       fname := filepath.Join(typesDir, "type_config.json")
+       t.Cleanup(func() {
+               os.RemoveAll(typesDir)
+       })
+       if err = os.WriteFile(fname, []byte(typeDefinition), 0666); err != nil {
+               t.Errorf("Unable to create temporary config file for types due to: %v", err)
+       }
+
+       types, err := GetJobTypesFromConfiguration(fname)
+
+       wantedType := TypeDefinition{
+               Id:            "type1",
+               DmaapTopicURL: "events/unauthenticated.SEC_FAULT_OUTPUT/dmaapmediatorproducer/type1",
+       }
+       wantedTypes := []TypeDefinition{wantedType}
+       assertions.EqualValues(wantedTypes, types)
+       assertions.Nil(err)
+}