From adad89a30ec77fca06a125dfb5f9199ca3bdc5be Mon Sep 17 00:00:00 2001 From: Andrea Lamparelli Date: Thu, 22 Feb 2024 16:02:00 +0100 Subject: [PATCH] fix TestMetadataValue* Signed-off-by: Andrea Lamparelli --- internal/converter/mlmd_converter_util_test.go | 17 +++++++---------- .../converter/mlmd_openapi_converter_util.go | 7 +++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/internal/converter/mlmd_converter_util_test.go b/internal/converter/mlmd_converter_util_test.go index a9e87ad4..91f44fee 100644 --- a/internal/converter/mlmd_converter_util_test.go +++ b/internal/converter/mlmd_converter_util_test.go @@ -66,7 +66,7 @@ func TestMetadataValueBool(t *testing.T) { data := make(map[string]openapi.MetadataValue) key := "my bool" mdValue := true - data[key] = openapi.MetadataBoolValueAsMetadataValue(&openapi.MetadataBoolValue{BoolValue: mdValue}) + data[key] = openapi.MetadataBoolValueAsMetadataValue(NewMetadataBoolValue(mdValue)) roundTripAndAssert(t, data, key) } @@ -75,7 +75,7 @@ func TestMetadataValueInt(t *testing.T) { data := make(map[string]openapi.MetadataValue) key := "my int" mdValue := "987" - data[key] = openapi.MetadataIntValueAsMetadataValue(&openapi.MetadataIntValue{IntValue: mdValue}) + data[key] = openapi.MetadataIntValueAsMetadataValue(NewMetadataIntValue(mdValue)) roundTripAndAssert(t, data, key) } @@ -84,7 +84,7 @@ func TestMetadataValueIntFailure(t *testing.T) { data := make(map[string]openapi.MetadataValue) key := "my int" mdValue := "not a number" - data[key] = openapi.MetadataIntValueAsMetadataValue(&openapi.MetadataIntValue{IntValue: mdValue}) + data[key] = openapi.MetadataIntValueAsMetadataValue(NewMetadataIntValue(mdValue)) assertion := setup(t) asGRPC, err := MapOpenAPICustomProperties(&data) @@ -97,7 +97,7 @@ func TestMetadataValueDouble(t *testing.T) { data := make(map[string]openapi.MetadataValue) key := "my double" mdValue := 3.1415 - data[key] = openapi.MetadataDoubleValueAsMetadataValue(&openapi.MetadataDoubleValue{DoubleValue: mdValue}) + data[key] = openapi.MetadataDoubleValueAsMetadataValue(NewMetadataDoubleValue(mdValue)) roundTripAndAssert(t, data, key) } @@ -106,7 +106,7 @@ func TestMetadataValueString(t *testing.T) { data := make(map[string]openapi.MetadataValue) key := "my string" mdValue := "Hello, World!" - data[key] = openapi.MetadataStringValueAsMetadataValue(&openapi.MetadataStringValue{StringValue: mdValue}) + data[key] = openapi.MetadataStringValueAsMetadataValue(NewMetadataStringValue(mdValue)) roundTripAndAssert(t, data, key) } @@ -123,7 +123,7 @@ func TestMetadataValueStruct(t *testing.T) { t.Error(err) } b64 := base64.StdEncoding.EncodeToString(asJSON) - data[key] = openapi.MetadataStructValueAsMetadataValue(&openapi.MetadataStructValue{StructValue: b64}) + data[key] = openapi.MetadataStructValueAsMetadataValue(NewMetadataStructValue(b64)) roundTripAndAssert(t, data, key) } @@ -141,10 +141,7 @@ func TestMetadataValueProtoUnsupported(t *testing.T) { } b64 := base64.StdEncoding.EncodeToString(asJSON) typeDef := "map[string]openapi.MetadataValue" - data[key] = openapi.MetadataProtoValueAsMetadataValue(&openapi.MetadataProtoValue{ - Type: typeDef, - ProtoValue: b64, - }) + data[key] = openapi.MetadataProtoValueAsMetadataValue(NewMetadataProtoValue(typeDef, b64)) assertion := setup(t) asGRPC, err := MapOpenAPICustomProperties(&data) diff --git a/internal/converter/mlmd_openapi_converter_util.go b/internal/converter/mlmd_openapi_converter_util.go index 7c02c8ee..3c3bc4e4 100644 --- a/internal/converter/mlmd_openapi_converter_util.go +++ b/internal/converter/mlmd_openapi_converter_util.go @@ -42,6 +42,13 @@ func NewMetadataStructValue(value string) *openapi.MetadataStructValue { return result } +func NewMetadataProtoValue(typeDef string, value string) *openapi.MetadataProtoValue { + result := openapi.NewMetadataProtoValueWithDefaults() + result.Type = typeDef + result.ProtoValue = value + return result +} + // MapMLMDCustomProperties maps MLMD custom properties model to OpenAPI one func MapMLMDCustomProperties(source map[string]*proto.Value) (map[string]openapi.MetadataValue, error) { data := make(map[string]openapi.MetadataValue)