X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=dmaap-mediator-producer%2Finternal%2Fconfig%2Fconfig_test.go;h=0e081a82379477e2d8beb8b70ffbdeb9d5565452;hb=36acb0c596211d3d771deb421eb71a05b3489e84;hp=e66a8182c4476ef18b46c6ecc53a34433e7d342f;hpb=6f5d3d1eccb8a1857c645ba6bd0b5e1b89ca7088;p=nonrtric.git diff --git a/dmaap-mediator-producer/internal/config/config_test.go b/dmaap-mediator-producer/internal/config/config_test.go index e66a8182..0e081a82 100644 --- a/dmaap-mediator-producer/internal/config/config_test.go +++ b/dmaap-mediator-producer/internal/config/config_test.go @@ -114,6 +114,33 @@ func TestNew_envFaultyLogLevelConfigContainDefaultValues(t *testing.T) { assertions.Contains(logString, "Invalid log level: wrong. Log level will be Info!") } +func TestGetJobTypesFromConfiguration_fileOkShouldReturnSliceOfTypeDefinitions(t *testing.T) { + assertions := require.New(t) + typesDir := CreateTypeConfigFiles(t) + t.Cleanup(func() { + os.RemoveAll(typesDir) + }) + + var typeSchemaObj interface{} + json.Unmarshal([]byte(typeSchemaFileContent), &typeSchemaObj) + + types, err := GetJobTypesFromConfiguration(typesDir) + + wantedDMaaPType := TypeDefinition{ + Identity: "type1", + DMaaPTopicURL: "events/unauthenticated.SEC_FAULT_OUTPUT/dmaapmediatorproducer/type1", + TypeSchema: typeSchemaObj, + } + wantedKafkaType := TypeDefinition{ + Identity: "type2", + KafkaInputTopic: "TestTopic", + TypeSchema: typeSchemaObj, + } + wantedTypes := []TypeDefinition{wantedDMaaPType, wantedKafkaType} + assertions.EqualValues(wantedTypes, types) + assertions.Nil(err) +} + 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#", @@ -126,16 +153,12 @@ const typeSchemaFileContent = `{ "additionalProperties": false }` -func TestGetTypesFromConfiguration_fileOkShouldReturnSliceOfTypeDefinitions(t *testing.T) { - assertions := require.New(t) +func CreateTypeConfigFiles(t *testing.T) string { 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) } @@ -147,22 +170,5 @@ func TestGetTypesFromConfiguration_fileOkShouldReturnSliceOfTypeDefinitions(t *t 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(typesDir) - - wantedDMaaPType := TypeDefinition{ - Identity: "type1", - DMaaPTopicURL: "events/unauthenticated.SEC_FAULT_OUTPUT/dmaapmediatorproducer/type1", - TypeSchema: typeSchemaObj, - } - wantedKafkaType := TypeDefinition{ - Identity: "type2", - KafkaInputTopic: "TestTopic", - TypeSchema: typeSchemaObj, - } - wantedTypes := []TypeDefinition{wantedDMaaPType, wantedKafkaType} - assertions.EqualValues(wantedTypes, types) - assertions.Nil(err) + return typesDir }