Skip to content

Commit

Permalink
fix TestMetadataValue*
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
  • Loading branch information
lampajr committed Feb 22, 2024
1 parent d94f7f4 commit 96c9f30
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
17 changes: 7 additions & 10 deletions internal/converter/mlmd_converter_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions internal/converter/mlmd_openapi_converter_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 96c9f30

Please sign in to comment.