Skip to content

Commit

Permalink
Add functional test for resourceprovider registration (UDT) (#8079)
Browse files Browse the repository at this point in the history
# Description

-Update to Typespec for ResourceType, ResourceProviderSummary to update
defaultApiVersion to be optional field.
-Added test for resourceprovider registration which includes calls to
create, list and show resource provider.

## Type of change
- This pull request adds or changes features of Radius and has an
approved issue (#6688 ).

Fixes: Part of #6688

## Contributor checklist
Please verify that the PR meets the following requirements, where
applicable:

- [ ] An overview of proposed schema changes is included in a linked
GitHub issue.
- [ ] A design document PR is created in the [design-notes
repository](https://github.com/radius-project/design-notes/), if new
APIs are being introduced.
- [ ] If applicable, design document has been reviewed and approved by
Radius maintainers/approvers.
- [ ] 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.
- [ ] 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.
- [ ] 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.

Signed-off-by: lakshmimsft <[email protected]>
  • Loading branch information
lakshmimsft authored Nov 25, 2024
1 parent ca08b9b commit 0aa2d6e
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pkg/ucp/api/v20231001preview/zz_generated_models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3975,8 +3975,7 @@
}
},
"required": [
"apiVersions",
"defaultApiVersion"
"apiVersions"
]
},
"ResourceTypeNameString": {
Expand All @@ -3998,10 +3997,7 @@
"$ref": "#/definitions/ApiVersionNameString",
"description": "The default api version for the resource type."
}
},
"required": [
"defaultApiVersion"
]
}
},
"ResourceTypeResource": {
"type": "object",
Expand Down
75 changes: 75 additions & 0 deletions test/functional-portable/ucp/noncloud/resourceprovider_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
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 ucp

import (
"encoding/json"
"testing"

"github.com/radius-project/radius/test/radcli"
"github.com/radius-project/radius/test/rp"
"github.com/radius-project/radius/test/testcontext"
"github.com/stretchr/testify/require"
)

func Test_ResourceProviderRegistration(t *testing.T) {
ctx, cancel := testcontext.NewWithCancel(t)
t.Cleanup(cancel)

options := rp.NewTestOptions(t)
cli := radcli.NewCLI(t, options.ConfigFilePath)

// Setup test data.
const (
manifestPath = "testdata/resourceprovider.yaml"
resourceProviderName = "MyCompany.Resources"
expectedResourceTypeName = "testResources"
expectedApiVersion = "2025-01-01-preview"
)

expectedData := map[string]any{
"name": resourceProviderName,
"locations": map[string]any{
"global": map[string]any{},
},
"resourceTypes": map[string]any{
expectedResourceTypeName: map[string]any{
"apiVersions": map[string]any{
expectedApiVersion: map[string]any{},
},
},
},
}

// Create the resource provider using the manifest.
_, err := cli.RunCommand(ctx, []string{"resource-provider", "create", "--from-file", manifestPath})
require.NoError(t, err)

// List resource providers.
output, err := cli.RunCommand(ctx, []string{"resource-provider", "list"})
require.NoError(t, err)
require.Contains(t, output, resourceProviderName)

// Show details of the resource provider.
output, err = cli.RunCommand(ctx, []string{"resource-provider", "show", resourceProviderName, "--output", "json"})
require.NoError(t, err)

var data map[string]any
err = json.Unmarshal([]byte(output), &data)
require.NoError(t, err)
require.Equal(t, expectedData, data)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: MyCompany.Resources
types:
testResources:
apiVersions:
"2025-01-01-preview":
schema: {}
capabilities: ["Recipes"]
4 changes: 2 additions & 2 deletions typespec/UCP/resourceproviders.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ model ResourceTypeProperties {
provisioningState?: ProvisioningState;

@doc("The default api version for the resource type.")
defaultApiVersion: ApiVersionNameString;
defaultApiVersion?: ApiVersionNameString;
}

@doc("The resource type for defining an API version of a resource type supported by the containing resource provider.")
Expand Down Expand Up @@ -168,7 +168,7 @@ model ResourceProviderSummaryResourceType {
apiVersions: Record<ResourceTypeSummaryResultApiVersion>;

@doc("The default api version for the resource type.")
defaultApiVersion: string;
defaultApiVersion?: string;
}

@doc("The configuration of a resource type API version.")
Expand Down

0 comments on commit 0aa2d6e

Please sign in to comment.