Skip to content

Commit

Permalink
converter: restrict captures to prefix when mapping *FromOwned
Browse files Browse the repository at this point in the history
Fixes: kubeflow#255

Signed-off-by: Isabella do Amaral <idoamara@redhat.com>
  • Loading branch information
isinyaaa committed Aug 26, 2024
1 parent 70a24f8 commit c8d7180
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
15 changes: 12 additions & 3 deletions internal/converter/mlmd_converter_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ func TestPrefixWhenOwnedWithoutOwner(t *testing.T) {
assertion.Equal("name", strings.Split(prefixed, ":")[1])
}

func TestPrefixNameWithColonWhenOwned(t *testing.T) {
assertion := setup(t)

owner := "owner"
entity := "name:with:colon"
assertion.Equal("owner:name:with:colon", PrefixWhenOwned(&owner, entity))
}

func TestMapRegisteredModelProperties(t *testing.T) {
assertion := setup(t)

Expand Down Expand Up @@ -578,7 +586,7 @@ func TestMapNameFromOwned(t *testing.T) {
assertion.Equal("name", *name)

name = MapNameFromOwned(of("prefix:name:postfix"))
assertion.Equal("name", *name)
assertion.Equal("name:postfix", *name)

name = MapNameFromOwned(nil)
assertion.Nil(name)
Expand All @@ -594,8 +602,9 @@ func TestMapRegisteredModelIdFromOwned(t *testing.T) {
_, err = MapRegisteredModelIdFromOwned(of("name"))
assertion.NotNil(err)

_, err = MapRegisteredModelIdFromOwned(of("prefix:name:postfix"))
assertion.NotNil(err)
result, err = MapRegisteredModelIdFromOwned(of("prefix:name:postfix"))
assertion.Nil(err)
assertion.Equal("prefix", result)

result, err = MapRegisteredModelIdFromOwned(nil)
assertion.Nil(err)
Expand Down
6 changes: 4 additions & 2 deletions internal/converter/mlmd_openapi_converter_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ func MapNameFromOwned(source *string) *string {
if len(exploded) == 1 {
return source
}
return &exploded[1]
// cat remaining parts of the exploded string
joined := strings.Join(exploded[1:], ":")
return &joined
}

// MapName derive the entity name from the mlmd fullname
Expand All @@ -124,7 +126,7 @@ func MapRegisteredModelIdFromOwned(source *string) (string, error) {
}

exploded := strings.Split(*source, ":")
if len(exploded) != 2 {
if len(exploded) < 2 {
return "", fmt.Errorf("wrong owned format")
}
return exploded[0], nil
Expand Down

0 comments on commit c8d7180

Please sign in to comment.