diff --git a/pkg/cli/cmd/resourceprovider/create/create.go b/pkg/cli/cmd/resourceprovider/create/create.go index 5534a8912a..162bef3c76 100644 --- a/pkg/cli/cmd/resourceprovider/create/create.go +++ b/pkg/cli/cmd/resourceprovider/create/create.go @@ -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 { diff --git a/pkg/cli/manifest/registermanifest.go b/pkg/cli/manifest/registermanifest.go index 1ceca54f72..289f96d5e5 100644 --- a/pkg/cli/manifest/registermanifest.go +++ b/pkg/cli/manifest/registermanifest.go @@ -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 @@ -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 ( diff --git a/pkg/cli/manifest/registermanifest_test.go b/pkg/cli/manifest/registermanifest_test.go index 8657f546c8..cc2c1ec525 100644 --- a/pkg/cli/manifest/registermanifest_test.go +++ b/pkg/cli/manifest/registermanifest_test.go @@ -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 @@ -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", @@ -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", diff --git a/pkg/cli/manifest/testclientfactory.go b/pkg/cli/manifest/testclientfactory.go index d5c1962e49..85e9117d1f 100644 --- a/pkg/cli/manifest/testclientfactory.go +++ b/pkg/cli/manifest/testclientfactory.go @@ -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 @@ -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 ( @@ -60,7 +65,6 @@ func NewTestClientFactory() (*v20231001preview.ClientFactory, error) { }, } - // Create other fake servers similarly resourceTypesServer := ucpfake.ResourceTypesServer{ BeginCreateOrUpdate: func( ctx context.Context, diff --git a/pkg/cli/manifest/registerdirectory_testdata/resourceprovider-valid1.yaml b/pkg/cli/manifest/testdata/registerdirectory/resourceprovider-valid1.yaml similarity index 100% rename from pkg/cli/manifest/registerdirectory_testdata/resourceprovider-valid1.yaml rename to pkg/cli/manifest/testdata/registerdirectory/resourceprovider-valid1.yaml diff --git a/pkg/cli/manifest/registerdirectory_testdata/resourceprovider-valid2.yaml b/pkg/cli/manifest/testdata/registerdirectory/resourceprovider-valid2.yaml similarity index 100% rename from pkg/cli/manifest/registerdirectory_testdata/resourceprovider-valid2.yaml rename to pkg/cli/manifest/testdata/registerdirectory/resourceprovider-valid2.yaml diff --git a/pkg/ucp/integrationtests/resourceproviders/resourceproviders_test.go b/pkg/ucp/integrationtests/resourceproviders/resourceproviders_test.go index 7ad93f4096..820debc187 100644 --- a/pkg/ucp/integrationtests/resourceproviders/resourceproviders_test.go +++ b/pkg/ucp/integrationtests/resourceproviders/resourceproviders_test.go @@ -19,7 +19,9 @@ 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" ) @@ -27,6 +29,11 @@ import ( 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) { @@ -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") +} diff --git a/pkg/ucp/integrationtests/resourceproviders/testdata/manifests/resourceprovider-valid1.yaml b/pkg/ucp/integrationtests/resourceproviders/testdata/manifests/resourceprovider-valid1.yaml new file mode 100644 index 0000000000..2d7d03ca75 --- /dev/null +++ b/pkg/ucp/integrationtests/resourceproviders/testdata/manifests/resourceprovider-valid1.yaml @@ -0,0 +1,7 @@ +name: TestProvider.TestCompany +types: + testResourcesAbc: + apiVersions: + "2023-10-01-preview": + schema: {} + capabilities: [] diff --git a/pkg/ucp/integrationtests/resourceproviders/testdata/resourceprovider_manifest_list_responsebody.json b/pkg/ucp/integrationtests/resourceproviders/testdata/resourceprovider_manifest_list_responsebody.json new file mode 100644 index 0000000000..e195fb5706 --- /dev/null +++ b/pkg/ucp/integrationtests/resourceproviders/testdata/resourceprovider_manifest_list_responsebody.json @@ -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" + } + ] +} diff --git a/pkg/ucp/integrationtests/resourceproviders/testdata/resourceprovider_manifest_requestbody.json b/pkg/ucp/integrationtests/resourceproviders/testdata/resourceprovider_manifest_requestbody.json new file mode 100644 index 0000000000..a3aab8e0f6 --- /dev/null +++ b/pkg/ucp/integrationtests/resourceproviders/testdata/resourceprovider_manifest_requestbody.json @@ -0,0 +1,5 @@ +{ + "location": "global", + "tags": {}, + "properties": {} +} diff --git a/pkg/ucp/integrationtests/resourceproviders/testdata/resourceprovider_manifest_responsebody.json b/pkg/ucp/integrationtests/resourceproviders/testdata/resourceprovider_manifest_responsebody.json new file mode 100644 index 0000000000..c8e010d3a9 --- /dev/null +++ b/pkg/ucp/integrationtests/resourceproviders/testdata/resourceprovider_manifest_responsebody.json @@ -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" +} diff --git a/pkg/ucp/integrationtests/resourceproviders/testdata/resourcetype_manifest_list_responsebody.json b/pkg/ucp/integrationtests/resourceproviders/testdata/resourcetype_manifest_list_responsebody.json new file mode 100644 index 0000000000..765c7f29cd --- /dev/null +++ b/pkg/ucp/integrationtests/resourceproviders/testdata/resourcetype_manifest_list_responsebody.json @@ -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" + } + ] +} diff --git a/pkg/ucp/integrationtests/resourceproviders/testdata/resourcetype_manifest_requestbody.json b/pkg/ucp/integrationtests/resourceproviders/testdata/resourcetype_manifest_requestbody.json new file mode 100644 index 0000000000..b4924988b0 --- /dev/null +++ b/pkg/ucp/integrationtests/resourceproviders/testdata/resourcetype_manifest_requestbody.json @@ -0,0 +1,5 @@ +{ + "properties": { + "defaultApiVersion": "2023-10-01" + } +} diff --git a/pkg/ucp/integrationtests/resourceproviders/testdata/resourcetype_manifest_responsebody.json b/pkg/ucp/integrationtests/resourceproviders/testdata/resourcetype_manifest_responsebody.json new file mode 100644 index 0000000000..e4bd9c9e25 --- /dev/null +++ b/pkg/ucp/integrationtests/resourceproviders/testdata/resourcetype_manifest_responsebody.json @@ -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" +} diff --git a/pkg/ucp/integrationtests/resourceproviders/util_test.go b/pkg/ucp/integrationtests/resourceproviders/util_test.go index 3378a8281a..79af09a374 100644 --- a/pkg/ucp/integrationtests/resourceproviders/util_test.go +++ b/pkg/ucp/integrationtests/resourceproviders/util_test.go @@ -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) { @@ -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)