Skip to content

Commit

Permalink
Fix rad group show and rad group list (#6252)
Browse files Browse the repository at this point in the history
# Description

This PR updates the JSONPath mappings for resource groups. Fixes a
regression introduced by #6191

## Type of change

<!--

Please select **one** of the following options that describes your
change and delete the others. Clearly identifying the type of change you
are making will help us review your PR faster, and is used in authoring
release notes.

If you are making a bug fix or functionality change to Radius and do not
have an associated issue link please create one now.

-->

- This pull request fixes a bug in Radius and has an approved issue
(issue link required).

<!--

Please update the following to link the associated issue. This is
required for some kinds of changes (see above).

-->

Fixes: #6249

## Auto-generated summary

<!--
GitHub Copilot for docs will auto-generate a summary of the PR
-->

<!--
copilot:all
-->
### <samp>🤖 Generated by Copilot at 47c16a4</samp>

### Summary
🐛🧪📦

<!--
1. 🐛 - This emoji represents a bug fix, which is what the JSONPath
corrections are.
2. 🧪 - This emoji represents a test, which is what the new test case for
the `list` command is.
3. 📦 - This emoji represents a package, which is what the imported
packages for the test setup and output formatting are.
-->
Added a CLI test for listing resource groups and fixed JSONPath
expressions for the output format.

> _To fix the JSONPath expressions_
> _They used the right capitalizations_
> _They also wrote a test_
> _For the CLI list_
> _With mocks and some table creations_

### Walkthrough
* Correct the JSONPath expressions for the `ResourceGroupResource`
struct in the `table` format options
([link](https://github.com/radius-project/radius/pull/6252/files?diff=unified&w=0#diff-f2e80353ac2e49da41bc04958b9568c662162f7dbb52ada2c328851436925482L81-R85))
* Import the `objectformats` and `to` packages to use the
`GetResourceGroupTableFormat` function and the `to.Ptr` helper function
in the `group list` command test
([link](https://github.com/radius-project/radius/pull/6252/files?diff=unified&w=0#diff-b6f63f3ed2aaeada863bd788b630879282e34fce2ad6672636ea677a37748853L27-R30))
* Create a mock API response with a slice of `ResourceGroupResource`
objects in the `group list` command test
([link](https://github.com/radius-project/radius/pull/6252/files?diff=unified&w=0#diff-b6f63f3ed2aaeada863bd788b630879282e34fce2ad6672636ea677a37748853R107-R118))
* Define the expected output as a slice of `FormattedOutput` objects
with the `table` format and the `GetResourceGroupTableFormat` options in
the `group list` command test
([link](https://github.com/radius-project/radius/pull/6252/files?diff=unified&w=0#diff-b6f63f3ed2aaeada863bd788b630879282e34fce2ad6672636ea677a37748853R130-R138))
* Compare the expected output with the actual output from the
`outputSink` in the `group list` command test
([link](https://github.com/radius-project/radius/pull/6252/files?diff=unified&w=0#diff-b6f63f3ed2aaeada863bd788b630879282e34fce2ad6672636ea677a37748853R130-R138))
  • Loading branch information
AaronCrawfis authored Oct 5, 2023
1 parent 33c51ed commit 6932c11
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
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 }",
},
},
}
Expand Down

0 comments on commit 6932c11

Please sign in to comment.