Skip to content

Commit

Permalink
add a test and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nithyatsu committed Jan 7, 2025
1 parent 32e73c9 commit 1d71f5d
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 19 deletions.
4 changes: 2 additions & 2 deletions pkg/cli/clivalidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ func RequireResourceTypeNameArgs(cmd *cobra.Command, args []string) (string, err
return "", err
}
if resourceType == "" {
return "", fmt.Errorf("resource type name is not provided or is empty ")
return "", fmt.Errorf("resource type name is not provided or is empty")
}

return resourceType, nil
Expand All @@ -474,7 +474,7 @@ func RequireResourceTypeNameArgs(cmd *cobra.Command, args []string) (string, err
// ReadResourceTypeNameArgs is used to get the resource type name that is supplied as the first argument
func ReadResourceTypeNameArgs(cmd *cobra.Command, args []string) (string, error) {
if len(args) < 1 {
return "", errors.New("no resource type name provided")
return "", errors.New("resource type name is provided")
}
return args[0], nil
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/cli/cmd/resourcetype/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func NewRunner(factory framework.Factory) *Runner {

// Validate runs validation for the `rad resourceprovider create` command.
func (r *Runner) Validate(cmd *cobra.Command, args []string) error {
// Validate command line args and
resourceTypeName, err := cli.RequireResourceTypeNameArgs(cmd, args)
if err != nil {
return err
Expand Down Expand Up @@ -137,7 +136,7 @@ func (r *Runner) Run(ctx context.Context) error {
}
}

//response, err := r.UCPClientFactory.NewResourceProvidersClient().Get(ctx, "local", r.ResourceProvider.Name, nil)
// If resource provider does not exist or if there is any other error, first register the resource provider.
response, err := r.UCPClientFactory.NewResourceTypesClient().Get(ctx, "local", r.ResourceProvider.Name, r.ResourceTypeName, nil)
if err != nil {
r.Output.LogInfo("Resource provider %q not found.", r.ResourceProvider.Name)
Expand Down
6 changes: 3 additions & 3 deletions pkg/cli/cmd/resourcetype/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ func Test_Validate(t *testing.T) {
ConfigHolder: framework.ConfigHolder{Config: config},
},
{
Name: "Invalid: Error in manifest",
Input: []string{"testResources", "--from-file", "testdata/missing-required-field.yaml"},
Name: "Invalid: resource type not present in manifest",
Input: []string{"myResources", "--from-file", "testdata/valid.yaml"},
ExpectedValid: false,
ConfigHolder: framework.ConfigHolder{Config: config},
},
{
Name: "Invalid: missing arguments",
Name: "Invalid: missing resource type as argument",
Input: []string{"--from-file", "testdata/valid.yaml"},
ExpectedValid: false,
ConfigHolder: framework.ConfigHolder{Config: config},
Expand Down

This file was deleted.

8 changes: 4 additions & 4 deletions pkg/cli/cmd/resourcetype/create/testdata/valid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: CoolCompany.Resources
types:
testResources:
apiVersions:
'2025-01-01-preview':
'2023-10-01-preview':
schema: {}
capabilities: ["Recipes"]
capabilities: ["Recipes"]
coolResources:
apiVersions:
'2025-01-01-preview':
'2023-10-01-preview':
schema: {}
capabilities: ["Recipes"]
capabilities: ["Recipes"]
4 changes: 2 additions & 2 deletions pkg/cli/manifest/registermanifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func RegisterType(ctx context.Context, clientFactory *v20231001preview.ClientFac
// Check if the type exists in the manifest file
resourceType, ok := resourceProvider.Types[typeName]
if !ok {
return fmt.Errorf("type %s not found in manifest file %s", typeName, filePath)
return fmt.Errorf("Type %s not found in manifest file %s", typeName, filePath)
}

logIfEnabled(logger, "Creating resource type %s/%s", resourceProvider.Name, typeName)
Expand All @@ -195,7 +195,7 @@ func RegisterType(ctx context.Context, clientFactory *v20231001preview.ClientFac
return err
}

// get the existing location resource and update it
// get the existing location resource and update it with new resource type. We have to revisit this code once schema is finalized and validated.
locationResourceGetResponse, err := clientFactory.NewLocationsClient().Get(ctx, planeName, resourceProvider.Name, v1.LocationGlobal, nil)
if err != nil {
return err
Expand Down

0 comments on commit 1d71f5d

Please sign in to comment.