Skip to content

Commit

Permalink
adding integration test
Browse files Browse the repository at this point in the history
Signed-off-by: lakshmimsft <[email protected]>
  • Loading branch information
lakshmimsft committed Dec 21, 2024
1 parent f325b57 commit 2975a86
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 4 deletions.
3 changes: 2 additions & 1 deletion pkg/cli/cmd/resourceprovider/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ func (r *Runner) Validate(cmd *cobra.Command, args []string) error {

// Run runs the `rad resource-provider create` command.
func (r *Runner) Run(ctx context.Context) error {
// Initialize the client factory
// Initialize the client factory if it hasn't been set externally.
// This allows for flexibility where a test UCPClientFactory can be set externally during testing.
if r.UCPClientFactory == nil {
err := r.initializeClientFactory(ctx, r.Workspace)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions pkg/cli/manifest/registermanifest.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/*
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
Expand All @@ -9,6 +13,7 @@ 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 manifest

import (
Expand Down
8 changes: 6 additions & 2 deletions pkg/cli/manifest/registermanifest_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/*
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
Expand Down Expand Up @@ -36,7 +40,7 @@ func TestRegisterDirectory(t *testing.T) {
{
name: "Success",
planeName: "local",
directoryPath: "registerdirectory_testdata",
directoryPath: "testdata/registerdirectory",
expectError: false,
expectedErrorMessage: "",
expectedResourceProvider: "MyCompany2.CompanyName2",
Expand Down Expand Up @@ -104,7 +108,7 @@ func TestRegisterFile(t *testing.T) {
{
name: "Success",
planeName: "local",
filePath: "registerdirectory_testdata/resourceprovider-valid2.yaml",
filePath: "testdata/registerdirectory/resourceprovider-valid2.yaml",
expectError: false,
expectedErrorMessage: "",
expectedResourceProvider: "MyCompany2.CompanyName2",
Expand Down
6 changes: 5 additions & 1 deletion pkg/cli/manifest/testclientfactory.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/*
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
Expand All @@ -9,6 +13,7 @@ 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 manifest

import (
Expand Down Expand Up @@ -60,7 +65,6 @@ func NewTestClientFactory() (*v20231001preview.ClientFactory, error) {
},
}

// Create other fake servers similarly
resourceTypesServer := ucpfake.ResourceTypesServer{
BeginCreateOrUpdate: func(
ctx context.Context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,21 @@ package resourceproviders
import (
"net/http"
"testing"
"time"

"github.com/radius-project/radius/pkg/ucp"
"github.com/radius-project/radius/pkg/ucp/testhost"
"github.com/stretchr/testify/require"
)

const (
resourceProviderEmptyListResponseFixture = "testdata/resourceprovider_v20231001preview_emptylist_responsebody.json"
resourceProviderListResponseFixture = "testdata/resourceprovider_v20231001preview_list_responsebody.json"

manifestResourceProviderListResponseFixture = "testdata/resourceprovider_manifest_list_responsebody.json"
manifestResourceProviderResponseFixture = "testdata/resourceprovider_manifest_responsebody.json"

manifestResourceTypeListResponseFixture = "testdata/resourcetype_manifest_list_responsebody.json"
)

func Test_ResourceProvider_Lifecycle(t *testing.T) {
Expand Down Expand Up @@ -87,3 +94,31 @@ func Test_ResourceProvider_CascadingDelete(t *testing.T) {
response.EqualsErrorCode(404, "NotFound")
require.Equal(t, locationID, response.Error.Error.Target)
}

func Test_ResourceProvider_RegisterManifests(t *testing.T) {
server := testhost.Start(t, testhost.TestHostOptionFunc(func(options *ucp.Options) {
options.Config.Initialization.ManifestDirectory = "testdata/manifests"
}))
defer server.Close()

createRadiusPlane(server)

require.Eventuallyf(t, func() bool {

// List should contain the resource provider and resource type in the manifest
response := server.MakeRequest(http.MethodGet, manifestResourceProviderCollectionURL, nil)
response.EqualsFixture(200, manifestResourceProviderListResponseFixture)

response = server.MakeRequest(http.MethodGet, manifestResourceProviderURL, nil)
response.EqualsFixture(200, manifestResourceProviderResponseFixture)

response = server.MakeRequest(http.MethodGet, manifestResourceTypeCollectionURL, nil)
response.EqualsFixture(200, manifestResourceTypeListResponseFixture)

response = server.MakeRequest(http.MethodGet, manifestResourceTypeURL, nil)
response.EqualsFixture(200, manifestResourceTypeResponseFixture)

deleteManifestResourceProvider(server)
return true
}, 30*time.Second, 3*time.Second, "manifest not registered")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: TestProvider.TestCompany
types:
testResourcesAbc:
apiVersions:
"2023-10-01-preview":
schema: {}
capabilities: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"value": [
{
"id": "/planes/radius/local/providers/System.Resources/resourceproviders/TestProvider.TestCompany",
"location": "global",
"name": "TestProvider.TestCompany",
"properties": {
"provisioningState": "Succeeded"
},
"tags": {},
"type": "System.Resources/resourceproviders"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"location": "global",
"tags": {},
"properties": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "/planes/radius/local/providers/System.Resources/resourceproviders/TestProvider.TestCompany",
"location": "global",
"name": "TestProvider.TestCompany",
"properties": {
"provisioningState": "Succeeded"
},
"tags": {},
"type": "System.Resources/resourceproviders"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"value": [
{
"id": "/planes/radius/local/providers/System.Resources/resourceproviders/TestProvider.TestCompany/resourcetypes/testResourcesAbc",
"name": "testResourcesAbc",
"properties": {
"provisioningState": "Succeeded"
},
"type": "System.Resources/resourceproviders/resourcetypes"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"properties": {
"defaultApiVersion": "2023-10-01"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "/planes/radius/local/providers/System.Resources/resourceproviders/TestProvider.TestCompany/resourcetypes/testResourcesAbc",
"name": "testResourcesAbc",
"properties": {
"provisioningState": "Succeeded"
},
"type": "System.Resources/resourceproviders/resourcetypes"
}
20 changes: 20 additions & 0 deletions pkg/ucp/integrationtests/resourceproviders/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ const (

resourceProviderSummaryCollectionURL = "/planes/radius/local/providers" + radiusAPIVersion
resourceProviderSummaryURL = "/planes/radius/local/providers/" + resourceProviderNamespace + radiusAPIVersion

manifestNamespace = "TestProvider.TestCompany"
manifestResourceProviderID = "/planes/radius/local/providers/System.Resources/resourceproviders/" + manifestNamespace
manifestResourceProviderCollectionURL = "/planes/radius/local/providers/System.Resources/resourceproviders" + radiusAPIVersion
manifestResourceProviderURL = manifestResourceProviderID + radiusAPIVersion

manifestResourceTypeName1 = "testResourcesAbc"
manifestResourceTypeID = manifestResourceProviderID + "/resourcetypes/" + manifestResourceTypeName1
manifestResourceTypeCollectionURL = manifestResourceProviderID + "/resourcetypes" + radiusAPIVersion
manifestResourceTypeURL = manifestResourceTypeID + radiusAPIVersion
manifestResourceTypeRequestFixture = "testdata/resourcetype_manifest_requestbody.json"
manifestResourceTypeResponseFixture = "testdata/resourcetype_manifest_responsebody.json"
)

func createRadiusPlane(server *testhost.TestHost) {
Expand All @@ -80,6 +92,14 @@ func deleteResourceProvider(server *testhost.TestHost) {
response.EqualsStatusCode(404)
}

func deleteManifestResourceProvider(server *testhost.TestHost) {
response := server.MakeRequest("DELETE", manifestResourceProviderURL, nil)
response.WaitForOperationComplete(nil)

response = server.MakeRequest("GET", manifestResourceProviderURL, nil)
response.EqualsStatusCode(404)
}

func createResourceType(server *testhost.TestHost) {
response := server.MakeFixtureRequest("PUT", resourceTypeURL, resourceTypeRequestFixture)
response.WaitForOperationComplete(nil)
Expand Down

0 comments on commit 2975a86

Please sign in to comment.