-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update RequireResource to handle duplicate short names and proper ful…
…ly qualified names (also make life a little better for windows file system contributors) (#7134) # Description Updated clivalidation.RequireResourceType so that it can take either fully qualified names or short names.. and if a short name is used and there are duplicate short names display the list of matching short names. I also added a .gitattributes to the following folders so that their test files would maintain lf line ends instead of crlf line ends when cloned or pulled into a windows filesystem. * pkg/corperp/renderers/containers/testdata * pkg/recipes/terraform/config/testdata * pkg/recipes/terraform/testdata/.terraform/modules ## Type of change This pull request fixes a bug in Radius and has an approved issue Fixes: #7070 This pull request fixes a bug in Radius but its not an approved issue Fixes: #7121 --------- Signed-off-by: Josh <[email protected]>
- Loading branch information
Showing
8 changed files
with
132 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
Copyright 2024 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 cli | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/radius-project/radius/pkg/cli/clients" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_RequireResourceType(t *testing.T) { | ||
|
||
supportedTypes := []string{} | ||
|
||
for _, resourceType := range clients.ResourceTypesList { | ||
supportedType := strings.Split(resourceType, "/")[1] | ||
supportedTypes = append(supportedTypes, supportedType) | ||
} | ||
|
||
resourceTypesErrorString := strings.Join(supportedTypes, "\n") | ||
|
||
tests := []struct { | ||
name string | ||
args []string | ||
want string | ||
wantErr error | ||
}{ | ||
{ | ||
name: "No arguments", | ||
args: []string{}, | ||
want: "", | ||
wantErr: errors.New("no resource type provided"), | ||
}, | ||
{ | ||
name: "Supported resource type", | ||
args: []string{"mongoDatabases"}, | ||
want: "Applications.Datastores/mongoDatabases", | ||
wantErr: nil, | ||
}, | ||
{ | ||
name: "Multiple resource types", | ||
args: []string{"secretStores"}, | ||
want: "", | ||
wantErr: fmt.Errorf("multiple resource types match 'secretStores'. Please specify the full resource type and try again:\n\nApplications.Dapr/secretStores\nApplications.Core/secretStores\n"), | ||
}, | ||
{ | ||
name: "Unsupported resource type", | ||
args: []string{"unsupported"}, | ||
want: "", | ||
wantErr: fmt.Errorf("'unsupported' is not a valid resource type. Available Types are: \n\n" + resourceTypesErrorString + "\n"), | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := RequireResourceType(tt.args) | ||
if len(tt.want) > 0 { | ||
require.Equal(t, tt.want, got) | ||
} else { | ||
require.Equal(t, tt.wantErr, 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
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,4 @@ | ||
#test files should use lf line endings | ||
*.tf text eol=lf | ||
*.json text eol=lf | ||
*.yaml text eol=lf |
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,4 @@ | ||
#test files should use lf line endings | ||
*.tf text eol=lf | ||
*.json text eol=lf | ||
*.yaml text eol=lf |
4 changes: 4 additions & 0 deletions
4
pkg/recipes/terraform/testdata/.terraform/modules/.gitattributes
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,4 @@ | ||
#test files should use lf line endings | ||
*.tf text eol=lf | ||
*.json text eol=lf | ||
*.yaml text eol=lf |