Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rad group show and rad group list #6252

Merged
merged 7 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pkg/cli/cmd/group/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import (
"github.com/radius-project/radius/pkg/cli/clients"
"github.com/radius-project/radius/pkg/cli/connections"
"github.com/radius-project/radius/pkg/cli/framework"
"github.com/radius-project/radius/pkg/cli/objectformats"
"github.com/radius-project/radius/pkg/cli/output"
"github.com/radius-project/radius/pkg/cli/workspaces"
"github.com/radius-project/radius/pkg/to"
"github.com/radius-project/radius/pkg/ucp/api/v20231001preview"
"github.com/radius-project/radius/test/radcli"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -102,6 +104,18 @@ func Test_Run(t *testing.T) {

Name: "kind-kind",
}

groups := []v20231001preview.ResourceGroupResource{
{
Name: to.Ptr("rg1"),
ID: to.Ptr("/planes/radius/local/resourcegroups/rg1"),
},
{
Name: to.Ptr("rg2"),
ID: to.Ptr("/planes/radius/local/resourcegroups/rg2"),
},
}

outputSink := &output.MockOutput{}
runner := &Runner{
ConnectionFactory: &connections.MockFactory{ApplicationsManagementClient: appManagementClient},
Expand All @@ -113,6 +127,15 @@ func Test_Run(t *testing.T) {
err := runner.Run(context.Background())
require.NoError(t, err)

expected := []any{
output.FormattedOutput{
Format: "table",
Obj: groups,
Options: objectformats.GetResourceGroupTableFormat(),
},
}

require.Equal(t, expected, outputSink.Writes)
})

}
6 changes: 3 additions & 3 deletions pkg/cli/objectformats/objectformats.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ func GetResourceGroupTableFormat() output.FormatterOptions {
Columns: []output.Column{
{
Heading: "ID",
JSONPath: "{ .id }",
JSONPath: "{ .ID }",
},
{
Heading: "Name",
JSONPath: "{ .name }",
Heading: "NAME",
JSONPath: "{ .Name }",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious about why this fixes the issue. If this is based on JSON then the previous code was correct:

func (r ResourceGroupResource) MarshalJSON() ([]byte, error) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to delay merging this until we figure it out? Or can we merge this in to fix the bug?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fired this up in the debugger and understood what's going on.

My expectation was that the JSONPointer library would operate on the JSON representation of the data. It turns out that it doesn't. It operates on the Go structs. So the behavior and the fix makes sense, it's not just not what I would have designed 😆

},
},
}
Expand Down
Loading