Skip to content

Commit

Permalink
Use plane-scoped environment list in CLI (radius-project#5746)
Browse files Browse the repository at this point in the history
# Description

This change enables the plane-scoped list APIs for all resource types,
adds a functional test, and updates the rad CLI to use this
functionality for discovering environments in `rad init`.

When I was testing this out, I found that the OpenAPI validation was
blocking these API calls. I tested this before, and I'm not sure how I
didn't notice the break when I was enabling the APIs.

Since we don't have good coverage of this scenario I added some of the
first functional tests that make direct API calls.

## Issue reference

Fixes: #5609


## Auto-generated summary

<!--
GitHub Copilot for docs will auto-generate a summary of the PR
-->

<!--
copilot:all
-->
### <samp>🤖 Generated by Copilot at 5bb8287</samp>

### Summary
🔄🌐📜

<!--
1. 🔄 This emoji represents the refactoring and renaming of the `ucp`
package to `clients` and the `connections` package to use a new
management client type. It also implies the removal of circular
dependencies and the simplification of the code.
2. 🌐 This emoji represents the addition of code for testing the resource
list APIs at different scopes and for listing environments at plane
scope. It also implies the expansion of the functional test coverage and
the support for Azure scopes.
3. 📜 This emoji represents the changes to the validator package to
support multiple root scope prefixes for loading and validating
specifications. It also implies the improvement of the test cases and
the names for the routes and URLs.
-->
This pull request refactors the `ucp` package to `clients` to support
both UCP and Azure scopes, updates the validator to handle multiple root
scope prefixes for validating requests, and updates the CLI, frontend,
and test code to use the new types and functions from the `clients` and
`validator` packages. It also deletes the unused
`pkg/cli/azure/resource_groups.go` file.

> _Oh we're the coders of the azure sea_
> _And we work on the validator API_
> _We load the specs with multiple prefixes_
> _And we test the scopes with `LoadSpec` slices_

### Walkthrough
* Rename `ucp` package to `clients` and refactor management client type
and functions to handle both UCP and Azure scopes
([link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL17-R21),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL30),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL38-R43),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL64-R64),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL88-R88),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL104-R104),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL118-R118),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL132-R132),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL147-R147),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL161-R161),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL183-R183),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL206-R206),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL221-R221),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL236-R236),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL277-R277),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL292-R292),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL299-R299),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL317-R317),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL380-R380),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL403-R425),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL425-R440),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL470-R455),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL499-R484),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL514-R499),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL533-R518),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL548-R533),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-23443c20f46bfbb5ffda2f87efc0e56ecaea1ef964ed4fc9ee06fe584fcfedcaL574-R559),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-bf4e917446c73565ee6967f28bdd8e619c0d4fa40b215f195b840c021dd36ce9L25-R26),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-bf4e917446c73565ee6967f28bdd8e619c0d4fa40b215f195b840c021dd36ce9L237-R237),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-d4132acf041f5a0725d02f79003aca9ad44bc2829ec159cb704b927f13d7b916L32),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-d4132acf041f5a0725d02f79003aca9ad44bc2829ec159cb704b927f13d7b916L178-R177),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-9e95146df57858ee34b56448b4ccf0c1d234eac1611745e623aabdc6b7262af6L37-R38),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-9e95146df57858ee34b56448b4ccf0c1d234eac1611745e623aabdc6b7262af6L695-R696))
* Change `LoadSpec` function to accept multiple root scope prefixes and
update validator logic and tests accordingly
([link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-2bdfa10a8abd451bfb18e729290e9182d1b8e6280d8a9e47dd0ce70f6e8d48d6L65-R73),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-35a42847397e63ce68849a6460524de6b1e7d1758aad42fb75864bdfe7a0b94aL62-R70),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-dfb7e47b7c3b87c21cf5cf682dec097126f3276a8019a440cc0bd74855a074e7L90-R90),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-81569bb69d66820a78376e124c53f82893c72ca029646bd0acc7e6a8b27f7001L36-R51),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-81569bb69d66820a78376e124c53f82893c72ca029646bd0acc7e6a8b27f7001L51-R66),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-81569bb69d66820a78376e124c53f82893c72ca029646bd0acc7e6a8b27f7001L131-R137),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-81569bb69d66820a78376e124c53f82893c72ca029646bd0acc7e6a8b27f7001L142-R148),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-81569bb69d66820a78376e124c53f82893c72ca029646bd0acc7e6a8b27f7001L153-R159),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-81569bb69d66820a78376e124c53f82893c72ca029646bd0acc7e6a8b27f7001L160-R209),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-81569bb69d66820a78376e124c53f82893c72ca029646bd0acc7e6a8b27f7001L173-R219),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-81569bb69d66820a78376e124c53f82893c72ca029646bd0acc7e6a8b27f7001L189-R235),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-81569bb69d66820a78376e124c53f82893c72ca029646bd0acc7e6a8b27f7001L212-R258),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-81569bb69d66820a78376e124c53f82893c72ca029646bd0acc7e6a8b27f7001L235-R281),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-81569bb69d66820a78376e124c53f82893c72ca029646bd0acc7e6a8b27f7001L262-R308),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-81569bb69d66820a78376e124c53f82893c72ca029646bd0acc7e6a8b27f7001L285-R334),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-81569bb69d66820a78376e124c53f82893c72ca029646bd0acc7e6a8b27f7001L308-R357),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-81569bb69d66820a78376e124c53f82893c72ca029646bd0acc7e6a8b27f7001L331-R380),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-81569bb69d66820a78376e124c53f82893c72ca029646bd0acc7e6a8b27f7001L354-R403),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-81569bb69d66820a78376e124c53f82893c72ca029646bd0acc7e6a8b27f7001L377-R426),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-81569bb69d66820a78376e124c53f82893c72ca029646bd0acc7e6a8b27f7001L400-R449),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-9e26da263135bed45f84fb809a604e09c7b6b4fe84a9348d08058b1eb212afb2L43-R43),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-9e26da263135bed45f84fb809a604e09c7b6b4fe84a9348d08058b1eb212afb2L83-R83),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-9e26da263135bed45f84fb809a604e09c7b6b4fe84a9348d08058b1eb212afb2L89-R89),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-9e26da263135bed45f84fb809a604e09c7b6b4fe84a9348d08058b1eb212afb2L147-R153),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-7b8cf0fed92b04574159896aa3e609b874fb6822eb4943c56e1f07966c46c089L76-R76),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-40da5a0178b34c207217154cc7fa3d432882f52681d9e262e33bce27f0156b36L66-R70),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-40da5a0178b34c207217154cc7fa3d432882f52681d9e262e33bce27f0156b36L105-R121),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-72b68e1ff471fe9aca9629dd4becb6478d89f5dc5895ecc15dc6a04bb6cb2ebbR25),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-72b68e1ff471fe9aca9629dd4becb6478d89f5dc5895ecc15dc6a04bb6cb2ebbL31-R32),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-72b68e1ff471fe9aca9629dd4becb6478d89f5dc5895ecc15dc6a04bb6cb2ebbL39-R43),
[link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-72b68e1ff471fe9aca9629dd4becb6478d89f5dc5895ecc15dc6a04bb6cb2ebbL55-R109))
* Add functional tests for listing resources at different scopes in
`test/functional/corerp/api_test.go`
([link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-cca752b4f280ec903b138acce03f8c540f5f8505472835bafeaffbd02ff08480R1-R88))
* Delete unused file `pkg/cli/azure/resource_groups.go`
([link](https://github.com/project-radius/radius/pull/5746/files?diff=unified&w=0#diff-6d429b950191bfd1d0f0f94904e198cb9220cc76f276a7a7dc8d09b09b04463f))
  • Loading branch information
rynowak authored Jun 17, 2023
1 parent 491c638 commit fc088a4
Show file tree
Hide file tree
Showing 14 changed files with 324 additions and 184 deletions.
39 changes: 0 additions & 39 deletions pkg/cli/azure/resource_groups.go

This file was deleted.

102 changes: 42 additions & 60 deletions pkg/cli/ucp/ucp_management.go → pkg/cli/clients/management.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pkg/cli/clivalidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"path"
"strings"

"github.com/project-radius/radius/pkg/cli/clients"
"github.com/project-radius/radius/pkg/cli/clierrors"
"github.com/project-radius/radius/pkg/cli/config"
"github.com/project-radius/radius/pkg/cli/ucp"
"github.com/project-radius/radius/pkg/cli/workspaces"
"github.com/project-radius/radius/pkg/ucp/resources"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -235,7 +235,7 @@ func RequireResourceType(args []string) (string, error) {
}
resourceTypeName := args[0]
supportedTypes := []string{}
for _, resourceType := range ucp.ResourceTypesList {
for _, resourceType := range clients.ResourceTypesList {
supportedType := strings.Split(resourceType, "/")[1]
supportedTypes = append(supportedTypes, supportedType)
if strings.EqualFold(supportedType, resourceTypeName) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/cli/connections/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
cli_credential "github.com/project-radius/radius/pkg/cli/credential"
"github.com/project-radius/radius/pkg/cli/deployment"
"github.com/project-radius/radius/pkg/cli/kubernetes"
"github.com/project-radius/radius/pkg/cli/ucp"
"github.com/project-radius/radius/pkg/cli/workspaces"
"github.com/project-radius/radius/pkg/sdk"
sdkclients "github.com/project-radius/radius/pkg/sdk/clients"
Expand Down Expand Up @@ -175,7 +174,7 @@ func (*impl) CreateApplicationsManagementClient(ctx context.Context, workspace w
return nil, err
}

return &ucp.ARMApplicationsManagementClient{
return &clients.UCPApplicationsManagementClient{
// The client expects root scope without a leading /
RootScope: strings.TrimPrefix(workspace.Scope, resources.SegmentSeparator),
ClientOptions: sdk.NewClientOptions(connection),
Expand Down
10 changes: 9 additions & 1 deletion pkg/corerp/frontend/handler/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ func AddRoutes(ctx context.Context, router *mux.Router, pathBase string, isARM b
return err
}

specLoader, err := validator.LoadSpec(ctx, ProviderNamespaceName, swagger.SpecFiles, pathBase+resourceGroupPath, "rootScope")
// URLs may use either the subscription/plane scope or resource group scope.
//
// These paths are order sensitive and the longer path MUST be registered first.
prefixes := []string{
pathBase + resourceGroupPath,
pathBase,
}

specLoader, err := validator.LoadSpec(ctx, ProviderNamespaceName, swagger.SpecFiles, prefixes, "rootScope")
if err != nil {
return err
}
Expand Down
10 changes: 9 additions & 1 deletion pkg/linkrp/frontend/handler/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ func AddRoutes(ctx context.Context, router *mux.Router, pathBase string, isARM b
return err
}

specLoader, err := validator.LoadSpec(ctx, ProviderNamespaceName, swagger.SpecFiles, pathBase+resourceGroupPath, "rootScope")
// URLs may use either the subscription/plane scope or resource group scope.
//
// These paths are order sensitive and the longer path MUST be registered first.
prefixes := []string{
pathBase + resourceGroupPath,
pathBase,
}

specLoader, err := validator.LoadSpec(ctx, ProviderNamespaceName, swagger.SpecFiles, prefixes, "rootScope")
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ucp/frontend/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func Register(ctx context.Context, router *mux.Router, ctrlOpts ctrl.Options) er
logger := ucplog.FromContextOrDiscard(ctx)
logger.Info(fmt.Sprintf("Registering routes with base path: %s", baseURL))

specLoader, err := validator.LoadSpec(ctx, "ucp", swagger.SpecFilesUCP, baseURL, "")
specLoader, err := validator.LoadSpec(ctx, "ucp", swagger.SpecFilesUCP, []string{baseURL}, "")
if err != nil {
return err
}
Expand Down
116 changes: 81 additions & 35 deletions pkg/validator/apivalidator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,37 @@ import (
)

const (
envRoute = "/providers/applications.core/environments/{environmentName}"
armIDUrl = "http://localhost:8080/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/radius-test-rg/providers/applications.core/environments/env0"
ucpIDUrl = "http://localhost:8080/planes/radius/local/resourceGroups/radius-test-rg/providers/applications.core/environments/env0"
longarmIDUrl = "http://localhost:8080/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/radius-test-rg/providers/applications.core/environments/largeEnvName14161820222426283032343638404244464850525456586062646668707274767880828486889092949698100102104106108120122124126128130"
longucpIDUrl = "http://localhost:8080/planes/radius/local/resourceGroups/radius-test-rg/providers/applications.core/environments/largeEnvName14161820222426283032343638404244464850525456586062646668707274767880828486889092949698100102104106108120122124126128130"
underscorearmIDUrl = "http://localhost:8080/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/radius-test-rg/providers/applications.core/environments/env_name0"
underscoreucpIDUrl = "http://localhost:8080/planes/radius/local/resourceGroups/radius-test-rg/providers/applications.core/environments/env_name0"
digitarmIDUrl = "http://localhost:8080/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/radius-test-rg/providers/applications.core/environments/0env"
digitucpIDUrl = "http://localhost:8080/planes/radius/local/resourceGroups/radius-test-rg/providers/applications.core/environments/0env"
environmentCollectionRoute = "/providers/applications.core/environments"
environmentResourceRoute = "/providers/applications.core/environments/{environmentName}"
armResourceGroupScopedResourceURL = "http://localhost:8080/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/radius-test-rg/providers/applications.core/environments/env0"
ucpResourceGroupScopedResourceURL = "http://localhost:8080/planes/radius/local/resourceGroups/radius-test-rg/providers/applications.core/environments/env0"
longARMResourceURL = "http://localhost:8080/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/radius-test-rg/providers/applications.core/environments/largeEnvName14161820222426283032343638404244464850525456586062646668707274767880828486889092949698100102104106108120122124126128130"
longUCPResourceURL = "http://localhost:8080/planes/radius/local/resourceGroups/radius-test-rg/providers/applications.core/environments/largeEnvName14161820222426283032343638404244464850525456586062646668707274767880828486889092949698100102104106108120122124126128130"
underscoreARMResourceURL = "http://localhost:8080/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/radius-test-rg/providers/applications.core/environments/env_name0"
underscoreUCPResourceURL = "http://localhost:8080/planes/radius/local/resourceGroups/radius-test-rg/providers/applications.core/environments/env_name0"
digitARMResourceURL = "http://localhost:8080/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/radius-test-rg/providers/applications.core/environments/0env"
digitUCPResourceURL = "http://localhost:8080/planes/radius/local/resourceGroups/radius-test-rg/providers/applications.core/environments/0env"

armResourceGroupScopedCollectionURL = "http://localhost:8080/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/radius-test-rg/providers/applications.core/environments"
armSubscriptionScopedCollectionURL = "http://localhost:8080/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/radius-test-rg/providers/applications.core/environments"
ucpResourceGroupScopeCollectionURL = "http://localhost:8080/planes/radius/local/providers/applications.core/environments"
ucpPlaneScopedCollectionURL = "http://localhost:8080/planes/radius/local/providers/applications.core/environments"

operationGetRoute = "/providers/applications.core/operations"
subscriptionPUTRoute = "/subscriptions/{subscriptions}/resourceGroups/{resourceGroup}"
)

func TestAPIValidator_ARMID(t *testing.T) {
runTest(t, armIDUrl)
func Test_APIValidator_ARMID(t *testing.T) {
runTest(t, armResourceGroupScopedResourceURL)
}

func TestAPIValidator_UCPID(t *testing.T) {
runTest(t, ucpIDUrl)
func Test_APIValidator_UCPID(t *testing.T) {
runTest(t, ucpResourceGroupScopedResourceURL)
}

func runTest(t *testing.T, resourceIDUrl string) {
// Load OpenAPI Spec for applications.core provider.
l, err := LoadSpec(context.Background(), "applications.core", swagger.SpecFiles, "/{rootScope:.*}", "rootScope")
l, err := LoadSpec(context.Background(), "applications.core", swagger.SpecFiles, []string{"/{rootScope:.*}"}, "rootScope")

require.NoError(t, err)

Expand Down Expand Up @@ -128,7 +134,7 @@ func runTest(t *testing.T, resourceIDUrl string) {
desc: "valid environment resource",
method: http.MethodPut,
rootScope: "/{rootScope:.*}",
route: envRoute,
route: environmentResourceRoute,
apiVersion: "2022-03-15-privatepreview",
contentFilePath: "put-environments-valid.json",
url: resourceIDUrl,
Expand All @@ -139,7 +145,7 @@ func runTest(t *testing.T, resourceIDUrl string) {
desc: "valid environment resource for selfhost",
method: http.MethodPut,
rootScope: "/{rootScope:.*}",
route: envRoute,
route: environmentResourceRoute,
apiVersion: "2022-03-15-privatepreview",
contentFilePath: "put-environments-valid-selfhost.json",
url: resourceIDUrl,
Expand All @@ -150,17 +156,57 @@ func runTest(t *testing.T, resourceIDUrl string) {
desc: "valid get-environment with azure resource id",
method: http.MethodGet,
rootScope: "/{rootScope:.*}",
route: envRoute,
route: environmentResourceRoute,
apiVersion: "2022-03-15-privatepreview",
url: resourceIDUrl,
responseCode: http.StatusAccepted,
validationErr: nil,
},
{
desc: "valid list-environment with azure resource group",
method: http.MethodGet,
rootScope: "/{rootScope:.*}",
route: environmentCollectionRoute,
apiVersion: "2022-03-15-privatepreview",
url: armResourceGroupScopedCollectionURL,
responseCode: http.StatusAccepted,
validationErr: nil,
},
{
desc: "valid list-environment with azure subscription",
method: http.MethodGet,
rootScope: "/{rootScope:.*}",
route: environmentCollectionRoute,
apiVersion: "2022-03-15-privatepreview",
url: armSubscriptionScopedCollectionURL,
responseCode: http.StatusAccepted,
validationErr: nil,
},
{
desc: "valid list-environment with UCP resource group",
method: http.MethodGet,
rootScope: "/{rootScope:.*}",
route: environmentCollectionRoute,
apiVersion: "2022-03-15-privatepreview",
url: ucpResourceGroupScopeCollectionURL,
responseCode: http.StatusAccepted,
validationErr: nil,
},
{
desc: "valid list-environment with UCP plane",
method: http.MethodGet,
rootScope: "/{rootScope:.*}",
route: environmentCollectionRoute,
apiVersion: "2022-03-15-privatepreview",
url: ucpPlaneScopedCollectionURL,
responseCode: http.StatusAccepted,
validationErr: nil,
},
{
desc: "valid delete-environment with azure resource id",
method: http.MethodDelete,
rootScope: "/{rootScope:.*}",
route: envRoute,
route: environmentResourceRoute,
apiVersion: "2022-03-15-privatepreview",
url: resourceIDUrl,
responseCode: http.StatusAccepted,
Expand All @@ -170,7 +216,7 @@ func runTest(t *testing.T, resourceIDUrl string) {
desc: "invalid put-environment with invalid api-version",
method: http.MethodPut,
rootScope: "/{rootScope:.*}",
route: envRoute,
route: environmentResourceRoute,
apiVersion: "2022-06-20-privatepreview", // unsupported api version
contentFilePath: "put-environments-valid.json",
url: resourceIDUrl,
Expand All @@ -186,7 +232,7 @@ func runTest(t *testing.T, resourceIDUrl string) {
desc: "invalid put-environment with missing location property bag",
method: http.MethodPut,
rootScope: "/{rootScope:.*}",
route: envRoute,
route: environmentResourceRoute,
apiVersion: "2022-03-15-privatepreview",
contentFilePath: "put-environments-invalid-missing-location.json",
url: resourceIDUrl,
Expand All @@ -209,7 +255,7 @@ func runTest(t *testing.T, resourceIDUrl string) {
desc: "invalid put-environment with missing kind property",
method: http.MethodPut,
rootScope: "/{rootScope:.*}",
route: envRoute,
route: environmentResourceRoute,
apiVersion: "2022-03-15-privatepreview",
contentFilePath: "put-environments-invalid-missing-kind.json",
url: resourceIDUrl,
Expand All @@ -232,7 +278,7 @@ func runTest(t *testing.T, resourceIDUrl string) {
desc: "invalid put-environment with multiple errors",
method: http.MethodPut,
rootScope: "/{rootScope:.*}",
route: envRoute,
route: environmentResourceRoute,
apiVersion: "2022-03-15-privatepreview",
contentFilePath: "put-environments-invalid-missing-locationandkind.json",
url: resourceIDUrl,
Expand All @@ -259,7 +305,7 @@ func runTest(t *testing.T, resourceIDUrl string) {
desc: "invalid put-environment with invalid json doc",
method: http.MethodPut,
rootScope: "/{rootScope:.*}",
route: envRoute,
route: environmentResourceRoute,
apiVersion: "2022-03-15-privatepreview",
contentFilePath: "put-environments-invalid-json.json",
url: resourceIDUrl,
Expand All @@ -282,10 +328,10 @@ func runTest(t *testing.T, resourceIDUrl string) {
desc: "env name too long",
method: http.MethodPut,
rootScope: "/{rootScope:.*}",
route: envRoute,
route: environmentResourceRoute,
apiVersion: "2022-03-15-privatepreview",
contentFilePath: "put-environments-valid.json",
url: longarmIDUrl,
url: longARMResourceURL,
responseCode: 400,
validationErr: &v1.ErrorResponse{
Error: v1.ErrorDetails{
Expand All @@ -305,10 +351,10 @@ func runTest(t *testing.T, resourceIDUrl string) {
desc: "env name too long",
method: http.MethodPut,
rootScope: "/{rootScope:.*}",
route: envRoute,
route: environmentResourceRoute,
apiVersion: "2022-03-15-privatepreview",
contentFilePath: "put-environments-valid.json",
url: longucpIDUrl,
url: longUCPResourceURL,
responseCode: 400,
validationErr: &v1.ErrorResponse{
Error: v1.ErrorDetails{
Expand All @@ -328,10 +374,10 @@ func runTest(t *testing.T, resourceIDUrl string) {
desc: "underscore not allowed in name",
method: http.MethodPut,
rootScope: "/{rootScope:.*}",
route: envRoute,
route: environmentResourceRoute,
apiVersion: "2022-03-15-privatepreview",
contentFilePath: "put-environments-valid.json",
url: underscorearmIDUrl,
url: underscoreARMResourceURL,
responseCode: 400,
validationErr: &v1.ErrorResponse{
Error: v1.ErrorDetails{
Expand All @@ -351,10 +397,10 @@ func runTest(t *testing.T, resourceIDUrl string) {
desc: "underscore not allowed in name",
method: http.MethodPut,
rootScope: "/{rootScope:.*}",
route: envRoute,
route: environmentResourceRoute,
apiVersion: "2022-03-15-privatepreview",
contentFilePath: "put-environments-valid.json",
url: underscoreucpIDUrl,
url: underscoreUCPResourceURL,
responseCode: 400,
validationErr: &v1.ErrorResponse{
Error: v1.ErrorDetails{
Expand All @@ -374,10 +420,10 @@ func runTest(t *testing.T, resourceIDUrl string) {
desc: "name cannot start with digit",
method: http.MethodPut,
rootScope: "/{rootScope:.*}",
route: envRoute,
route: environmentResourceRoute,
apiVersion: "2022-03-15-privatepreview",
contentFilePath: "put-environments-valid.json",
url: digitarmIDUrl,
url: digitARMResourceURL,
responseCode: 400,
validationErr: &v1.ErrorResponse{
Error: v1.ErrorDetails{
Expand All @@ -397,10 +443,10 @@ func runTest(t *testing.T, resourceIDUrl string) {
desc: "name cannot start with digit",
method: http.MethodPut,
rootScope: "/{rootScope:.*}",
route: envRoute,
route: environmentResourceRoute,
apiVersion: "2022-03-15-privatepreview",
contentFilePath: "put-environments-valid.json",
url: digitucpIDUrl,
url: digitUCPResourceURL,
responseCode: 400,
validationErr: &v1.ErrorResponse{
Error: v1.ErrorDetails{
Expand Down
Loading

0 comments on commit fc088a4

Please sign in to comment.