-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resource type create - fixes (#8248)
# Description Fixes below issues in resource-type create - APIversion for the created resource-type was blank. - Display of the resource-type created at the end of the command was incorrect - Added UTs that would have caught these issues. - sample manifest updated to have just one resource-type ## Type of change - This pull request fixes a bug in Radius and has an approved issue (issue link required). - This pull request is a minor refactor, code cleanup, test improvement, or other maintenance task and doesn't change the functionality of Radius (issue link optional) Fixes: #issue_number ## Contributor checklist Please verify that the PR meets the following requirements, where applicable: - [ NA ] An overview of proposed schema changes is included in a linked GitHub issue. - [ NA ] A design document PR is created in the [design-notes repository](https://github.com/radius-project/design-notes/), if new APIs are being introduced. - [ NA ] If applicable, design document has been reviewed and approved by Radius maintainers/approvers. - [ NA ] A PR for the [samples repository](https://github.com/radius-project/samples) is created, if existing samples are affected by the changes in this PR. - [ NA ] A PR for the [documentation repository](https://github.com/radius-project/docs) is created, if the changes in this PR affect the documentation or any user facing updates are made. - [ NA ] A PR for the [recipes repository](https://github.com/radius-project/recipes) is created, if existing recipes are affected by the changes in this PR.
- Loading branch information
Showing
10 changed files
with
339 additions
and
60 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
Copyright 2023 The Radius Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package common | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
|
||
"github.com/radius-project/radius/pkg/cli/clients" | ||
"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" | ||
"go.uber.org/mock/gomock" | ||
) | ||
|
||
func Test_GetResourceTypeDetails(t *testing.T) { | ||
t.Run("Get Resource Details Success", func(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
resourceProvider := v20231001preview.ResourceProviderSummary{ | ||
Name: to.Ptr("Applications.Test"), | ||
ResourceTypes: map[string]*v20231001preview.ResourceProviderSummaryResourceType{ | ||
"exampleResources": { | ||
APIVersions: map[string]map[string]any{ | ||
"2023-10-01-preview": {}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
appManagementClient := clients.NewMockApplicationsManagementClient(ctrl) | ||
appManagementClient.EXPECT(). | ||
GetResourceProviderSummary(gomock.Any(), "local", "Applications.Test"). | ||
Return(resourceProvider, nil). | ||
Times(1) | ||
|
||
res, err := GetResourceTypeDetails(context.Background(), "Applications.Test", "exampleResources", appManagementClient) | ||
require.NoError(t, err) | ||
require.Equal(t, "Applications.Test/exampleResources", res.Name) | ||
|
||
}) | ||
|
||
t.Run("Get Resource Details Failure - Resource Provider Not found", func(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
appManagementClient := clients.NewMockApplicationsManagementClient(ctrl) | ||
appManagementClient.EXPECT(). | ||
GetResourceProviderSummary(gomock.Any(), "local", "Applications.Test"). | ||
Return(v20231001preview.ResourceProviderSummary{}, radcli.Create404Error()). | ||
Times(1) | ||
|
||
_, err := GetResourceTypeDetails(context.Background(), "Applications.Test", "exampleResources", appManagementClient) | ||
|
||
require.Error(t, err) | ||
require.Equal(t, "The resource provider \"Applications.Test\" was not found or has been deleted.", err.Error()) | ||
}) | ||
|
||
t.Run("Get Resource Details Failures Other Than Not Found", func(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
appManagementClient := clients.NewMockApplicationsManagementClient(ctrl) | ||
appManagementClient.EXPECT(). | ||
GetResourceProviderSummary(gomock.Any(), "local", "Applications.Test"). | ||
Return(v20231001preview.ResourceProviderSummary{}, errors.New("some error occurred")). | ||
Times(1) | ||
|
||
_, err := GetResourceTypeDetails(context.Background(), "Applications.Test", "exampleResources", appManagementClient) | ||
|
||
require.Error(t, err) | ||
}) | ||
} |
This file contains 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
Oops, something went wrong.