Skip to content

Commit

Permalink
no metadata response
Browse files Browse the repository at this point in the history
  • Loading branch information
gvicentin committed Jun 10, 2024
1 parent eec9a21 commit bcfed93
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
4 changes: 4 additions & 0 deletions cmd/plugin/rpaasv2/cmd/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func writeMetadata(w io.Writer, metadata *types.Metadata) {
fmt.Fprintf(w, " %s: %s\n", v.Name, v.Value)
}
}

if len(metadata.Labels) == 0 && len(metadata.Annotations) == 0 {
fmt.Fprintf(w, "No metadata found\n")
}
}

func runGetMetadata(c *cli.Context) error {
Expand Down
31 changes: 21 additions & 10 deletions cmd/plugin/rpaasv2/cmd/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,24 @@ func TestGetMetadata(t *testing.T) {

client := &fake.FakeClient{
FakeGetMetadata: func(instance string) (*types.Metadata, error) {
if instance != "my-instance" {
if instance == "my-instance" {
return &types.Metadata{
Labels: []types.MetadataItem{
{Name: "label1", Value: "value1"},
},
Annotations: []types.MetadataItem{
{Name: "annotation1", Value: "value1"},
{Name: "annotation2", Value: "value2"},
},
}, nil
} else if instance == "empty-instance" {
return &types.Metadata{
Labels: []types.MetadataItem{},
Annotations: []types.MetadataItem{},
}, nil
} else {
return nil, errors.New("could not find instance")
}
return &types.Metadata{
Labels: []types.MetadataItem{
{Name: "label1", Value: "value1"},
},
Annotations: []types.MetadataItem{
{Name: "annotation1", Value: "value1"},
{Name: "annotation2", Value: "value2"},
},
}, nil
},
}

Expand All @@ -56,6 +62,11 @@ Annotations:
instance: "invalid-instance",
expectedErr: "could not find instance",
},
{
name: "get metadata with no content",
instance: "empty-instance",
expected: "No metadata found\n",
},
}

for _, tt := range testCases {
Expand Down

0 comments on commit bcfed93

Please sign in to comment.