X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=dmaap-mediator-producer%2Finternal%2Fconfig%2Fconfig_test.go;h=293e0d0b4d2897f05bccb86b0c380fc3be862dda;hb=f4969908aee0d89693e127a242005f88cdabc586;hp=9420a2ad19e6b856ef1a3e430c806a02c93e7dce;hpb=c4960f1dc6688b039d6ee29da03e0c0de47b6fbb;p=nonrtric.git diff --git a/dmaap-mediator-producer/internal/config/config_test.go b/dmaap-mediator-producer/internal/config/config_test.go index 9420a2ad..293e0d0b 100644 --- a/dmaap-mediator-producer/internal/config/config_test.go +++ b/dmaap-mediator-producer/internal/config/config_test.go @@ -23,7 +23,7 @@ package config import ( "bytes" "os" - "reflect" + "path/filepath" "testing" log "github.com/sirupsen/logrus" @@ -72,12 +72,11 @@ func TestNew_faultyIntValueSetConfigContainDefaultValueAndWarnInLog(t *testing.T InfoProducerPort: 8085, InfoCoordinatorAddress: "https://enrichmentservice:8434", DMaaPMRAddress: "https://message-router.onap:3905", - ProducerCertPath: "configs/producer.crt", - ProducerKeyPath: "configs/producer.key", - } - if got := New(); !reflect.DeepEqual(got, &wantConfig) { - t.Errorf("New() = %v, want %v", got, &wantConfig) + 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") } @@ -99,8 +98,8 @@ func TestNew_envFaultyLogLevelConfigContainDefaultValues(t *testing.T) { InfoProducerPort: 8085, InfoCoordinatorAddress: "https://enrichmentservice:8434", DMaaPMRAddress: "https://message-router.onap:3905", - ProducerCertPath: "configs/producer.crt", - ProducerKeyPath: "configs/producer.key", + ProducerCertPath: "security/producer.crt", + ProducerKeyPath: "security/producer.key", } got := New() @@ -109,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) +}