Skip to content

Commit

Permalink
Tests for ARM, adds TrackedResource (#588)
Browse files Browse the repository at this point in the history
* arm test

* implement ARM simulator

* use mock value

* nested

* fix tests

fix mockapi.ts

fix

* changelog

* changeset

* expect value, format

* use ProxyResource for child resource

* format using node 18

* pnpm-lock.yaml

* Revert "pnpm-lock.yaml"

This reverts commit 4da25a3.

* Revert "format using node 18"

This reverts commit a08469f.

* change directory

* revert package.json

* fix scenario doc

* cadl-ranch-summary.md

* add armCommonTypesVersion

* use commonTypeVersion on version parameter

* remove from global namespace
  • Loading branch information
XiaofeiCao authored Jun 18, 2024
1 parent d983279 commit 8b42129
Show file tree
Hide file tree
Showing 6 changed files with 1,081 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/short-owls-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@azure-tools/cadl-ranch-specs": minor
---

Added tests for ARM's tracked resource and nested resource.
337 changes: 337 additions & 0 deletions packages/cadl-ranch-specs/cadl-ranch-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,343 @@ Expects header 'x-ms-api-key': 'valid-key'

Expects header 'authorization': 'Bearer https://security.microsoft.com/.default'

### Azure_Arm_Models_Resources_NestedProxyResources_createOrReplace

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

Resource PUT operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested
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/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested",
"name": "nested",
"type": "nested",
"properties":{
"description": "valid",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}
```

### Azure_Arm_Models_Resources_NestedProxyResources_delete

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

Resource DELETE operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested
Expected query parameter: api-version=2023-12-01-preview
Expected response status code: 204

### Azure_Arm_Models_Resources_NestedProxyResources_get

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

Resource GET operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested
Expected query parameter: api-version=2023-12-01-preview

Expected response body:

```json
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested",
"name": "nested",
"type": "nested",
"properties":{
"description": "valid",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}
```

### Azure_Arm_Models_Resources_NestedProxyResources_listByTopLevelTrackedResource

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

Resource LIST by parent resource operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested
Expected query parameter: api-version=2023-12-01-preview

Expected response body:

```json
{
"value": [{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested",
"name": "nested",
"type": "nested",
"properties":{
"description": "valid",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}]
}
```

### Azure_Arm_Models_Resources_NestedProxyResources_update

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

Resource PATCH operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested
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/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested",
"name": "nested",
"type": "nested",
"properties":{
"description": "valid2",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}
```

### Azure_Arm_Models_Resources_TopLevelTrackedResources_createOrReplace

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

Resource PUT operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top
Expected query parameter: api-version=2023-12-01-preview
Expected request body:

```json
{
"location": "eastus",
"properties": {
"description": "valid"
}
}
```

Expected response body:

```json
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top",
"name": "top",
"type": "topLevel",
"location": "eastus",
"properties": {
"description": "valid",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}
```

### Azure_Arm_Models_Resources_TopLevelTrackedResources_delete

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

Resource DELETE operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top
Expected query parameter: api-version=2023-12-01-preview

````
Expected response status code: 204
### Azure_Arm_Models_Resources_TopLevelTrackedResources_get
- Endpoint: `get https://management.azure.com`
Resource GET operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top
Expected query parameter: api-version=2023-12-01-preview
Expected response body:
```json
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top",
"name": "top",
"type": "topLevel",
"location": "eastus",
"properties":{
"description": "valid",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}
````

### Azure_Arm_Models_Resources_TopLevelTrackedResources_listByResourceGroup

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

Resource LIST by resource group operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources
Expected query parameter: api-version=2023-12-01-preview

Expected response body:

```json
{
"value": [{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top",
"name": "top",
"type": "topLevel",
"location": "eastus",
"properties":{
"description": "valid",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}]
}
```

### Azure_Arm_Models_Resources_TopLevelTrackedResources_listBySubscription

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

Resource LIST by subscription operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources
Expected query parameter: api-version=2023-12-01-preview

Expected response body:

```json
{
"value": [{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top",
"name": "top",
"type": "topLevel",
"location": "eastus",
"properties":{
"description": "valid",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}]
}
```

### Azure_Arm_Models_Resources_TopLevelTrackedResources_update

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

Resource PATCH operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top
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/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top",
"name": "top",
"type": "topLevel",
"location": "eastus",
"properties":{
"description": "valid2",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}
```

### Azure_ClientGenerator_Core_Access_InternalOperation

- Endpoints:
Expand Down
39 changes: 39 additions & 0 deletions packages/cadl-ranch-specs/http/azure/arm/models/resources/main.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import "@azure-tools/cadl-ranch-expect";
import "@typespec/http";
import "@typespec/rest";
import "@typespec/versioning";
import "@azure-tools/typespec-azure-core";
import "@azure-tools/typespec-azure-resource-manager";
import "@azure-tools/typespec-client-generator-core";
import "./toplevel.tsp";
import "./nested.tsp";

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

@armProviderNamespace
@service
@versioned(Versions)
@doc("Arm Resource Provider management API.")
namespace Azure.Arm.Models.Resources;

@doc("Azure API versions.")
enum Versions {
@armCommonTypesVersion(CommonTypes.Versions.v5)
@useDependency(Azure.Core.Versions.v1_0_Preview_2)
@useDependency(Azure.ResourceManager.Versions.v1_0_Preview_1)
@doc("Preview API version 2023-12-01-preview.")
v2023_12_01_preview: "2023-12-01-preview",
}

union ProvisioningState {
ResourceProvisioningState,
Provisioning: "Provisioning",
Updating: "Updating",
Deleting: "Deleting",
Accepted: "Accepted",
}
Loading

0 comments on commit 8b42129

Please sign in to comment.