X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=dmaap-mediator-producer%2Finternal%2Fconfig%2Fconfig_test.go;h=e66a8182c4476ef18b46c6ecc53a34433e7d342f;hb=6f5d3d1eccb8a1857c645ba6bd0b5e1b89ca7088;hp=faf5900dbb7e00fcf38923f0737bc80baabfcb92;hpb=5feecd881172a3b22041d35443c1f946e7d5f63e;p=nonrtric.git diff --git a/dmaap-mediator-producer/internal/config/config_test.go b/dmaap-mediator-producer/internal/config/config_test.go index faf5900d..e66a8182 100644 --- a/dmaap-mediator-producer/internal/config/config_test.go +++ b/dmaap-mediator-producer/internal/config/config_test.go @@ -22,6 +22,7 @@ package config import ( "bytes" + "encoding/json" "os" "path/filepath" "testing" @@ -37,6 +38,7 @@ func TestNew_envVarsSetConfigContainSetValues(t *testing.T) { os.Setenv("INFO_PRODUCER_PORT", "8095") os.Setenv("INFO_COORD_ADDR", "infoCoordAddr") os.Setenv("DMAAP_MR_ADDR", "mrHost:3908") + os.Setenv("KAFKA_BOOTSTRAP_SERVERS", "localhost:9093") os.Setenv("PRODUCER_CERT_PATH", "cert") os.Setenv("PRODUCER_KEY_PATH", "key") t.Cleanup(func() { @@ -48,6 +50,7 @@ func TestNew_envVarsSetConfigContainSetValues(t *testing.T) { InfoProducerPort: 8095, InfoCoordinatorAddress: "infoCoordAddr", DMaaPMRAddress: "mrHost:3908", + KafkaBootstrapServers: "localhost:9093", ProducerCertPath: "cert", ProducerKeyPath: "key", } @@ -72,6 +75,7 @@ func TestNew_faultyIntValueSetConfigContainDefaultValueAndWarnInLog(t *testing.T InfoProducerPort: 8085, InfoCoordinatorAddress: "https://informationservice:8434", DMaaPMRAddress: "https://message-router.onap:3905", + KafkaBootstrapServers: "localhost:9092", ProducerCertPath: "security/producer.crt", ProducerKeyPath: "security/producer.key", } @@ -98,6 +102,7 @@ func TestNew_envFaultyLogLevelConfigContainDefaultValues(t *testing.T) { InfoProducerPort: 8085, InfoCoordinatorAddress: "https://informationservice:8434", DMaaPMRAddress: "https://message-router.onap:3905", + KafkaBootstrapServers: "localhost:9092", ProducerCertPath: "security/producer.crt", ProducerKeyPath: "security/producer.key", } @@ -109,7 +114,17 @@ func TestNew_envFaultyLogLevelConfigContainDefaultValues(t *testing.T) { 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"}]}` +const typeDefinition = `{"types": [{"id": "type1", "dmaapTopicUrl": "events/unauthenticated.SEC_FAULT_OUTPUT/dmaapmediatorproducer/type1"}, {"id": "type2", "kafkaInputTopic": "TestTopic"}]}` +const typeSchemaFileContent = `{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "filter": { + "type": "string" + } + }, + "additionalProperties": false + }` func TestGetTypesFromConfiguration_fileOkShouldReturnSliceOfTypeDefinitions(t *testing.T) { assertions := require.New(t) @@ -124,14 +139,30 @@ func TestGetTypesFromConfiguration_fileOkShouldReturnSliceOfTypeDefinitions(t *t if err = os.WriteFile(fname, []byte(typeDefinition), 0666); err != nil { t.Errorf("Unable to create temporary config file for types due to: %v", err) } + fname = filepath.Join(typesDir, "typeSchemaDmaap.json") + if err = os.WriteFile(fname, []byte(typeSchemaFileContent), 0666); err != nil { + t.Errorf("Unable to create temporary schema file for DMaaP type due to: %v", err) + } + fname = filepath.Join(typesDir, "typeSchemaKafka.json") + if err = os.WriteFile(fname, []byte(typeSchemaFileContent), 0666); err != nil { + t.Errorf("Unable to create temporary schema file for Kafka type due to: %v", err) + } + var typeSchemaObj interface{} + json.Unmarshal([]byte(typeSchemaFileContent), &typeSchemaObj) - types, err := GetJobTypesFromConfiguration(fname) + types, err := GetJobTypesFromConfiguration(typesDir) - wantedType := TypeDefinition{ - Id: "type1", - DmaapTopicURL: "events/unauthenticated.SEC_FAULT_OUTPUT/dmaapmediatorproducer/type1", + wantedDMaaPType := TypeDefinition{ + Identity: "type1", + DMaaPTopicURL: "events/unauthenticated.SEC_FAULT_OUTPUT/dmaapmediatorproducer/type1", + TypeSchema: typeSchemaObj, + } + wantedKafkaType := TypeDefinition{ + Identity: "type2", + KafkaInputTopic: "TestTopic", + TypeSchema: typeSchemaObj, } - wantedTypes := []TypeDefinition{wantedType} + wantedTypes := []TypeDefinition{wantedDMaaPType, wantedKafkaType} assertions.EqualValues(wantedTypes, types) assertions.Nil(err) }