-
Notifications
You must be signed in to change notification settings - Fork 120
Usability: rad recipe show does not show parameter values #11005
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
Open
Alec13355
wants to merge
7
commits into
radius-project:main
Choose a base branch
from
Alec13355:issue-9454
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
506acfd
Fixes issue where 'rad recipe show' displayed 'null' instead of
Alec13355 4b59285
chore(deps): bump securego/gosec from 538a05cc5d6eb7bb41624e48f6e5019…
dependabot[bot] 1f6878e
Add support for new 'x-radius-sensitive' annotation (#10999)
lakshmimsft fd12a37
Mocking framework all needs method registered or bombs out on test
Alec13355 d0beb81
Fix DE functional test workflow to be consistent with publish workflo…
willdavsmith cf6e2c1
Merge branch 'main' into issue-9454
Alec13355 b2afa63
Merge branch 'main' into issue-9454
brooke-hamilton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ package show | |
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "go.uber.org/mock/gomock" | ||
|
|
@@ -93,6 +94,19 @@ func Test_Validate(t *testing.T) { | |
| radcli.SharedValidateValidation(t, NewCommand, testcases) | ||
| } | ||
|
|
||
| // setupTestClient creates a mock client with default behavior for common calls | ||
| func setupTestClient(ctrl *gomock.Controller) *clients.MockApplicationsManagementClient { | ||
| appManagementClient := clients.NewMockApplicationsManagementClient(ctrl) | ||
|
|
||
| // Default behavior: GetEnvironment returns "not found" error (most common case) | ||
| appManagementClient.EXPECT(). | ||
| GetEnvironment(gomock.Any(), gomock.Any()). | ||
| Return(v20231001preview.EnvironmentResource{}, fmt.Errorf("not found")). | ||
| AnyTimes() | ||
|
|
||
brooke-hamilton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return appManagementClient | ||
| } | ||
|
|
||
| func Test_Run(t *testing.T) { | ||
| t.Run("Show bicep recipe details - Success", func(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
|
|
@@ -132,7 +146,7 @@ func Test_Run(t *testing.T) { | |
| }, | ||
| } | ||
|
|
||
| appManagementClient := clients.NewMockApplicationsManagementClient(ctrl) | ||
| appManagementClient := setupTestClient(ctrl) | ||
| appManagementClient.EXPECT(). | ||
| GetRecipeMetadata(gomock.Any(), gomock.Any(), gomock.Any()). | ||
| Return(envRecipe, nil).Times(1) | ||
|
|
@@ -209,7 +223,7 @@ func Test_Run(t *testing.T) { | |
| }, | ||
| } | ||
|
|
||
| appManagementClient := clients.NewMockApplicationsManagementClient(ctrl) | ||
| appManagementClient := setupTestClient(ctrl) | ||
| appManagementClient.EXPECT(). | ||
| GetRecipeMetadata(gomock.Any(), gomock.Any(), gomock.Any()). | ||
| Return(envRecipe, nil).Times(1) | ||
|
|
@@ -246,7 +260,7 @@ func Test_Run(t *testing.T) { | |
| require.Equal(t, expected, outputSink.Writes) | ||
| }) | ||
|
|
||
| t.Run("Show terraformn recipe details - Success", func(t *testing.T) { | ||
| t.Run("Show terraform recipe details - Success", func(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
| envRecipe := v20231001preview.RecipeGetMetadataResponse{ | ||
| TemplateKind: to.Ptr(recipes.TemplateKindTerraform), | ||
|
|
@@ -286,7 +300,7 @@ func Test_Run(t *testing.T) { | |
| }, | ||
| } | ||
|
|
||
| appManagementClient := clients.NewMockApplicationsManagementClient(ctrl) | ||
| appManagementClient := setupTestClient(ctrl) | ||
| appManagementClient.EXPECT(). | ||
| GetRecipeMetadata(gomock.Any(), gomock.Any(), gomock.Any()). | ||
| Return(envRecipe, nil).Times(1) | ||
|
|
@@ -322,4 +336,182 @@ func Test_Run(t *testing.T) { | |
| } | ||
| require.Equal(t, expected, outputSink.Writes) | ||
| }) | ||
|
|
||
| t.Run("Show recipe details with environment parameter values - Success", func(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
| envRecipe := v20231001preview.RecipeGetMetadataResponse{ | ||
| TemplateKind: to.Ptr(recipes.TemplateKindBicep), | ||
| TemplatePath: to.Ptr("ghcr.io/testpublicrecipe/bicep/modules/openai:v1"), | ||
| Parameters: map[string]any{ | ||
| "location": map[string]any{ | ||
| "type": "string", | ||
| "defaultValue": "null", | ||
| }, | ||
| "resource_group_name": map[string]any{ | ||
| "type": "string", | ||
| "defaultValue": "null", | ||
| }, | ||
| }, | ||
| } | ||
| recipe := types.EnvironmentRecipe{ | ||
| Name: "default", | ||
| ResourceType: "Radius.Resources/openAI", | ||
| TemplateKind: recipes.TemplateKindBicep, | ||
| TemplatePath: "ghcr.io/testpublicrecipe/bicep/modules/openai:v1", | ||
| } | ||
|
|
||
| // Environment has configured parameter values | ||
| envResource := v20231001preview.EnvironmentResource{ | ||
| Properties: &v20231001preview.EnvironmentProperties{ | ||
| Recipes: map[string]map[string]v20231001preview.RecipePropertiesClassification{ | ||
| "Radius.Resources/openAI": { | ||
| "default": &v20231001preview.BicepRecipeProperties{ | ||
| TemplateKind: to.Ptr(recipes.TemplateKindBicep), | ||
| TemplatePath: to.Ptr("ghcr.io/testpublicrecipe/bicep/modules/openai:v1"), | ||
| Parameters: map[string]any{ | ||
| "location": "eastus", | ||
| "resource_group_name": "my-rg", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| // Expected parameters should show environment values, not template defaults | ||
| recipeParams := []types.RecipeParameter{ | ||
| { | ||
| Name: "resource_group_name", | ||
| Type: "string", | ||
| MaxValue: "-", | ||
| MinValue: "-", | ||
| DefaultValue: "my-rg", // Environment value overrides template default | ||
| }, | ||
| { | ||
| Name: "location", | ||
| Type: "string", | ||
| MaxValue: "-", | ||
| MinValue: "-", | ||
| DefaultValue: "eastus", // Environment value overrides template default | ||
| }, | ||
| } | ||
|
|
||
| appManagementClient := clients.NewMockApplicationsManagementClient(ctrl) | ||
| appManagementClient.EXPECT(). | ||
| GetRecipeMetadata(gomock.Any(), gomock.Any(), gomock.Any()). | ||
| Return(envRecipe, nil).Times(1) | ||
|
|
||
| appManagementClient.EXPECT(). | ||
| GetEnvironment(gomock.Any(), gomock.Any()). | ||
| Return(envResource, nil).Times(1) | ||
|
|
||
| outputSink := &output.MockOutput{} | ||
|
|
||
| runner := &Runner{ | ||
| ConnectionFactory: &connections.MockFactory{ApplicationsManagementClient: appManagementClient}, | ||
| Output: outputSink, | ||
| Workspace: &workspaces.Workspace{}, | ||
| Format: "table", | ||
| RecipeName: "default", | ||
| ResourceType: "Radius.Resources/openAI", | ||
| } | ||
|
|
||
| err := runner.Run(context.Background()) | ||
| require.NoError(t, err) | ||
|
|
||
| expected := []any{ | ||
| output.FormattedOutput{ | ||
| Format: "table", | ||
| Obj: recipe, | ||
| Options: common.RecipeFormat(), | ||
| }, | ||
| output.LogOutput{ | ||
| Format: "", | ||
| }, | ||
| output.FormattedOutput{ | ||
| Format: "table", | ||
| Obj: recipeParams, | ||
| Options: common.RecipeParametersFormat(), | ||
| }, | ||
| } | ||
| require.Equal(t, expected, outputSink.Writes) | ||
| }) | ||
|
|
||
| t.Run("Show recipe details when GetEnvironment fails - Success", func(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
| envRecipe := v20231001preview.RecipeGetMetadataResponse{ | ||
| TemplateKind: to.Ptr(recipes.TemplateKindBicep), | ||
| TemplatePath: to.Ptr("ghcr.io/testpublicrecipe/bicep/modules/openai:v1"), | ||
| Parameters: map[string]any{ | ||
| "location": map[string]any{ | ||
| "type": "string", | ||
| "defaultValue": "westus", | ||
| }, | ||
| "resource_group_name": map[string]any{ | ||
| "type": "string", | ||
| "defaultValue": "null", | ||
| }, | ||
| }, | ||
| } | ||
| recipe := types.EnvironmentRecipe{ | ||
| Name: "default", | ||
| ResourceType: "Radius.Resources/openAI", | ||
| TemplateKind: recipes.TemplateKindBicep, | ||
| TemplatePath: "ghcr.io/testpublicrecipe/bicep/modules/openai:v1", | ||
| } | ||
|
|
||
| // Expected parameters should show template defaults since environment call fails | ||
| recipeParams := []types.RecipeParameter{ | ||
| { | ||
| Name: "resource_group_name", | ||
| Type: "string", | ||
| MaxValue: "-", | ||
| MinValue: "-", | ||
| DefaultValue: "null", // Template default since environment fails | ||
| }, | ||
| { | ||
| Name: "location", | ||
| Type: "string", | ||
| MaxValue: "-", | ||
| MinValue: "-", | ||
| DefaultValue: "westus", // Template default since environment fails | ||
| }, | ||
| } | ||
|
|
||
| appManagementClient := setupTestClient(ctrl) | ||
| appManagementClient.EXPECT(). | ||
| GetRecipeMetadata(gomock.Any(), gomock.Any(), gomock.Any()). | ||
| Return(envRecipe, nil).Times(1) | ||
|
|
||
| outputSink := &output.MockOutput{} | ||
|
|
||
| runner := &Runner{ | ||
| ConnectionFactory: &connections.MockFactory{ApplicationsManagementClient: appManagementClient}, | ||
| Output: outputSink, | ||
| Workspace: &workspaces.Workspace{}, | ||
| Format: "table", | ||
| RecipeName: "default", | ||
| ResourceType: "Radius.Resources/openAI", | ||
| } | ||
|
|
||
| err := runner.Run(context.Background()) | ||
| require.NoError(t, err) | ||
|
|
||
| expected := []any{ | ||
| output.FormattedOutput{ | ||
| Format: "table", | ||
| Obj: recipe, | ||
| Options: common.RecipeFormat(), | ||
| }, | ||
| output.LogOutput{ | ||
| Format: "", | ||
| }, | ||
| output.FormattedOutput{ | ||
| Format: "table", | ||
| Obj: recipeParams, | ||
| Options: common.RecipeParametersFormat(), | ||
| }, | ||
| } | ||
| require.Equal(t, expected, outputSink.Writes) | ||
| }) | ||
|
Comment on lines
+440
to
+516
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing nil check for
environment.Propertiesbefore accessingenvironment.Properties.Recipes. According to the EnvironmentResource struct definition, Properties is a pointer field that could be nil, which would cause a panic. Add a nil check for Properties before checking Recipes.