Skip to content
This repository has been archived by the owner on Jan 21, 2025. It is now read-only.

Test ARM, test case for location-based resource #703

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fair-socks-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@azure-tools/cadl-ranch-specs": patch
---

Added tests for ARM, test case for LocationResource.
150 changes: 150 additions & 0 deletions packages/cadl-ranch-specs/cadl-ranch-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,156 @@ Expected response body:
}
```

### Azure_ResourceManager_Models_Resources_LocationResources_createOrUpdate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to call this scenario Azure_ResourceManager_Models_Resources_Location_ResourceGroup_createOrUpdate
or
Azure_ResourceManager_Models_Resources_Location_ResourceGroupLocationResource_createOrUpdate,
since this PR covers ResourceGroupLocationResource, and we also have SubscriptionLocationResource and TenantLocationResource which we don't cover here.
@weidongxu-microsoft @tadelesh Would like your opinion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i prefer the shorter one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iscai-msft Here's another case where we may need @clientName:
We want the scenario name be Azure_ResourceManager_Models_Resources_Location_ResourceGroup_createOrUpdate, this may require an interface called ResourceGroup.
For generated SDK, it'll generate a client called ResourceGroup... This is not a big issue since it resides under the corresponding namespace, though still a bit weird to me...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@XiaofeiCao is it possible for you to compile a list of all of the categories and subcategories, so we can agree on the current ordering? Everything's getting long and confusing imo. Something like

Azure
 |-> ResourceManager
       |-> Models
             |-> Resources
       | -> CommonTypes 

For example, I don't think we need Models as a namespace

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iscai-msft Here's what's intended to be:

Azure
 |-> ResourceManager
       |-> Models
             |-> Resources // resources and their common CRUD operations
             |-> CommonTypes // special common-types like ManagedIdentity
                |-> ManagedIdentities
                |-> EncryptionProperties
                |-> SKUs, etc
       |-> Operations // uncommon operations, or operations with multiple scenarios, irrelavant of resource types
             |-> LROs(including pageable LROs)
             |-> Resource Actions //import, export, upload, trigger, etc
             |-> Resource Move // move resource to another subscription(not sure, maybe just in Resources is enough?)

Basically it's following this issue's structure, and typespec-azure's sample folder. Any suggestions are welcome too!

Models seems unnecessary, we could remove that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is my suggestion, @timotheeguerin please lmk your thoughts

Azure
 |-> ResourceManager
       |-> Resources // resources and their common CRUD operations
             |-> Actions
             |-> Move (?)
       |-> CommonTypes // special common-types like ManagedIdentity
          |-> ManagedIdentities
          |-> EncryptionProperties
          |-> SKUs, etc
       |-> Operations
             |-> LROs(including pageable LROs)


- Endpoint: `put https://management.azure.com`

Resource PUT operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/locations/eastus/providers/Azure.ResourceManager.Models.Resources/locationResources/resource
Expected query parameter: api-version=2023-12-01-preview
Expected request body:

```json
{
"properties": {
"description": "valid"
}
}
```

Expected response body:

```json
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/locations/eastus/providers/Azure.ResourceManager.Models.Resources/locationResources/resource",
"name": "resource",
"type": "Azure.ResourceManager.Models.Resources/locationResources",
"properties": {
"description": "valid",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}
```

### Azure_ResourceManager_Models_Resources_LocationResources_delete

- Endpoint: `delete https://management.azure.com`

Resource DELETE operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/locations/eastus/providers/Azure.ResourceManager.Models.Resources/locationResources/resource
Expected query parameter: api-version=2023-12-01-preview

````
Expected response status code: 204

### Azure_ResourceManager_Models_Resources_LocationResources_get

- Endpoint: `get https://management.azure.com`

Resource GET operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/locations/eastus/providers/Azure.ResourceManager.Models.Resources/locationResources/resource
Expected query parameter: api-version=2023-12-01-preview

Expected response body:
```json
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/locations/eastus/providers/Azure.ResourceManager.Models.Resources/locationResources/resource",
"name": "resource",
"type": "Azure.ResourceManager.Models.Resources/locationResources",
"properties":{
"description": "valid",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}
````

### Azure_ResourceManager_Models_Resources_LocationResources_listByParent

- Endpoint: `get https://management.azure.com`

Resource LIST by resource group operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/locations/eastus/providers/Azure.ResourceManager.Models.Resources/locationResources
Expected query parameter: api-version=2023-12-01-preview

Expected response body:

```json
{
"value": [{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/locations/eastus/providers/Azure.ResourceManager.Models.Resources/locationResources/resource",
"name": "resource",
"type": "Azure.ResourceManager.Models.Resources/locationResources",
"properties":{
"description": "valid",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}]
}
```

### Azure_ResourceManager_Models_Resources_LocationResources_update

- Endpoint: `patch https://management.azure.com`

Resource PATCH operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/locations/eastus/providers/Azure.ResourceManager.Models.Resources/locationResources/resource
Expected query parameter: api-version=2023-12-01-preview
Expected request body:

```json
{
"properties": {
"description": "valid2"
}
}
```

Expected response body:

```json
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/locations/eastus/providers/Azure.ResourceManager.Models.Resources/locationResources/resource",
"name": "resource",
"type": "Azure.ResourceManager.Models.Resources/locationResources",
"properties":{
"description": "valid2",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}
```

### Azure_ResourceManager_Models_Resources_NestedProxyResources_createOrReplace

- Endpoint: `put https://management.azure.com`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import "@typespec/http";
import "@typespec/rest";
import "@azure-tools/typespec-azure-core";
import "@azure-tools/typespec-azure-resource-manager";

using TypeSpec.Http;
using TypeSpec.Rest;
using Azure.Core;
using Azure.ResourceManager;
using TypeSpec.OpenAPI;

namespace Azure.ResourceManager.Models.Resources;

@locationResource
model LocationResource is ProxyResource<LocationResourceProperties> {
...ResourceNameParameter<LocationResource>;
}

/** Location resource properties */
model LocationResourceProperties {
@doc("The description of the resource.")
description?: string;

/** The status of the last operation. */
@visibility("read")
provisioningState?: ProvisioningState;
}

@armResourceOperations
interface LocationResources {
@scenario
@scenarioDoc("""
Resource GET operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/locations/eastus/providers/Azure.ResourceManager.Models.Resources/locationResources/resource
Expected query parameter: api-version=2023-12-01-preview

Expected response body:
```json
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/locations/eastus/providers/Azure.ResourceManager.Models.Resources/locationResources/resource",
"name": "resource",
"type": "Azure.ResourceManager.Models.Resources/locationResources",
"properties":{
"description": "valid",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}
```
""")
get is ArmResourceRead<LocationResource>;

@scenario
@scenarioDoc("""
Resource PUT operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/locations/eastus/providers/Azure.ResourceManager.Models.Resources/locationResources/resource
Expected query parameter: api-version=2023-12-01-preview
Expected request body:
```json
{
"properties": {
"description": "valid",
}
}
```
Expected response body:
```json
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/locations/eastus/providers/Azure.ResourceManager.Models.Resources/locationResources/resource",
"name": "resource",
"type": "Azure.ResourceManager.Models.Resources/locationResources",
"properties": {
"description": "valid",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}
```
""")
createOrUpdate is ArmResourceCreateOrUpdateAsync<LocationResource>;

@scenario
@scenarioDoc("""
Resource PATCH operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/locations/eastus/providers/Azure.ResourceManager.Models.Resources/locationResources/resource
Expected query parameter: api-version=2023-12-01-preview
Expected request body:
```json
{
"properties": {
"description": "valid2",
}
}
```
Expected response body:
```json
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/locations/eastus/providers/Azure.ResourceManager.Models.Resources/locationResources/resource",
"name": "resource",
"type": "Azure.ResourceManager.Models.Resources/locationResources",
"properties":{
"description": "valid2",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}
```
""")
update is ArmResourcePatchSync<LocationResource, LocationResourceProperties>;

@scenario
@scenarioDoc("""
Resource DELETE operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/locations/eastus/providers/Azure.ResourceManager.Models.Resources/locationResources/resource
Expected query parameter: api-version=2023-12-01-preview
```
Expected response status code: 204
""")
delete is ArmResourceDeleteSync<LocationResource>;

@scenario
@scenarioDoc("""
Resource LIST by resource group operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/locations/eastus/providers/Azure.ResourceManager.Models.Resources/locationResources
Expected query parameter: api-version=2023-12-01-preview

Expected response body:
```json
{
"value": [{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/locations/eastus/providers/Azure.ResourceManager.Models.Resources/locationResources/resource",
"name": "resource",
"type": "Azure.ResourceManager.Models.Resources/locationResources",
"properties":{
"description": "valid",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}]
}
```
""")
listByParent is ArmResourceListByParent<LocationResource>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "@azure-tools/typespec-azure-resource-manager";
import "@azure-tools/typespec-client-generator-core";
import "./toplevel.tsp";
import "./nested.tsp";
import "./location.tsp";
import "./singleton.tsp";

using TypeSpec.Http;
Expand Down
Loading
Loading