Skip to content

Commit

Permalink
Tests ARM, test case for listing available operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
v-hongli1 committed Aug 27, 2024
1 parent 697c3bc commit ba3d4ac
Show file tree
Hide file tree
Showing 4 changed files with 318 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-avocados-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@azure-tools/cadl-ranch-specs": patch
---

Tests ARM, test case for listing available operations
102 changes: 102 additions & 0 deletions packages/cadl-ranch-specs/cadl-ranch-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,108 @@ Expected response body:
}
```

### Azure_ResourceManager_Models_Resources_OperationStatuses_getResourceGroupStatus

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

Resource GET operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Models.Resources/locations/westus/operationStatuses/00000000-0000-0000-0000-000000000000
Expected query parameter: api-version=2023-12-01-preview

Expected response body:

```json
{
"name": "ResourceGroupOperation",
"startTime": <any date>,
"endTime": <any date>,
"percentComplete": 2,
"status": "Failed",
"ManagementError": {
"code": "404",
"message": "The error message of status test. ",
"target": "The target of status test.",
"details": [{
"code": "404",
"message": "The error message of status test. ",
"target": "The target of status test.",
}],
"additionalInfo": [{
"type": "additionalType",
"info": "additionalInfo"
}]
}
}
```

### Azure_ResourceManager_Models_Resources_OperationStatuses_getSubscriptionStatus

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

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

Expected response body:

```json
{
"name": "SubscriptionOperation",
"startTime": <any date>,
"endTime": <any date>,
"percentComplete": 2,
"status": "Failed",
"ManagementError": {
"code": "404",
"message": "The error message of status test. ",
"target": "The target of status test.",
"details": [{
"code": "404",
"message": "The error message of status test. ",
"target": "The target of status test.",
}],
"additionalInfo": [{
"type": "additionalType",
"info": "additionalInfo"
}]
}
}
```

### Azure_ResourceManager_Models_Resources_OperationStatuses_getTenantStatus

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

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

Expected response body:

```json
{
"name": "TenantOperation",
"startTime": <any date>,
"endTime": <any date>,
"percentComplete": 2,
"status": "Failed",
"ManagementError": {
"code": "404",
"message": "The error message of status test. ",
"target": "The target of status test.",
"details": [{
"code": "404",
"message": "The error message of status test. ",
"target": "The target of status test.",
}],
"additionalInfo": [{
"type": "additionalType",
"info": "additionalInfo"
}]
}
}
```

### Azure_ResourceManager_Models_Resources_SingletonTrackedResources_createOrUpdate

- Endpoint: `put https://management.azure.com`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,115 @@ union ProvisioningState {
Deleting: "Deleting",
Accepted: "Accepted",
}

@resource("operationStatuses")
@parentResource(TenantLocationResource)
model TenantOperationStatus is ArmOperationStatus;

@parentResource(SubscriptionLocationResource)
model SubscriptionOperationStatus is ArmOperationStatus;

@parentResource(ResourceGroupLocationResource)
model ResourceGroupOperationStatus is ArmOperationStatus;

@armResourceOperations
interface OperationStatuses {
@scenario
@scenarioDoc("""
Resource GET operation.
Expected path: /providers/Azure.ResourceManager.Models.Resources/locations/westus/operationStatuses/00000000-0000-0000-0000-000000000000
Expected query parameter: api-version=2023-12-01-preview
Expected response body:
```json
{
"name": "TenantOperation",
"startTime": <any date>,
"endTime": <any date>,
"percentComplete": 2,
"status": "Failed",
"ManagementError": {
"code": "404",
"message": "The error message of status test. ",
"target": "The target of status test.",
"details": [{
"code": "404",
"message": "The error message of status test. ",
"target": "The target of status test.",
}],
"additionalInfo": [{
"type": "additionalType",
"info": "additionalInfo"
}]
}
}
```
""")
getTenantStatus is ArmResourceRead<TenantOperationStatus>;

@scenario
@scenarioDoc("""
Resource GET operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/providers/Azure.ResourceManager.Models.Resources/locations/westus/operationStatuses/00000000-0000-0000-0000-000000000000
Expected query parameter: api-version=2023-12-01-preview
Expected response body:
```json
{
"name": "SubscriptionOperation",
"startTime": <any date>,
"endTime": <any date>,
"percentComplete": 2,
"status": "Failed",
"ManagementError": {
"code": "404",
"message": "The error message of status test. ",
"target": "The target of status test.",
"details": [{
"code": "404",
"message": "The error message of status test. ",
"target": "The target of status test.",
}],
"additionalInfo": [{
"type": "additionalType",
"info": "additionalInfo"
}]
}
}
```
""")
getSubscriptionStatus is ArmResourceRead<SubscriptionOperationStatus>;

@scenario
@scenarioDoc("""
Resource GET operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Models.Resources/locations/westus/operationStatuses/00000000-0000-0000-0000-000000000000
Expected query parameter: api-version=2023-12-01-preview
Expected response body:
```json
{
"name": "ResourceGroupOperation",
"startTime": <any date>,
"endTime": <any date>,
"percentComplete": 2,
"status": "Failed",
"ManagementError": {
"code": "404",
"message": "The error message of status test. ",
"target": "The target of status test.",
"details": [{
"code": "404",
"message": "The error message of status test. ",
"target": "The target of status test.",
}],
"additionalInfo": [{
"type": "additionalType",
"info": "additionalInfo"
}]
}
}
```
""")
getResourceGroupStatus is ArmResourceRead<ResourceGroupOperationStatus>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";
export const Scenarios: Record<string, ScenarioMockApi> = {};

const SUBSCRIPTION_ID_EXPECTED = "00000000-0000-0000-0000-000000000000";
const OPERATION_ID_EXPECTED = "12345678-1234-1234-1234-123456789000";
const RESOURCE_GROUP_EXPECTED = "test-rg";
const LOCATION_EXPECTED = "westus";
const validTopLevelResource = {
id: `/subscriptions/${SUBSCRIPTION_ID_EXPECTED}/resourceGroups/${RESOURCE_GROUP_EXPECTED}/providers/Azure.ResourceManager.Models.Resources/topLevelTrackedResources/top`,
name: "top",
Expand Down Expand Up @@ -61,6 +63,103 @@ const validSingletonResource = {
},
};

const validOperationStatus = {
name: "TenantOperation",
startTime: new Date(),
endTime: new Date(),
percentComplete: 2,
status: "Failed",
ManagementError: {
code: "404",
message: "The error message of status test. ",
target: "The target of status test.",
details: [
{
code: "404",
message: "The error message of status test. ",
target: "The target of status test.",
},
],
additionalInfo: [
{
type: "additionalType",
info: "additionalInfo",
},
],
},
};

// operation status
Scenarios.Azure_ResourceManager_Models_Resources_OperationStatuses_getTenantStatus = passOnSuccess([
mockapi.get(
"/providers/Azure.ResourceManager.Models.Resources/locations/:location/operationStatuses/:operationId",
(req) => {
req.expect.containsQueryParam("api-version", "2023-12-01-preview");
if (req.params.location !== LOCATION_EXPECTED) {
throw new ValidationError("Unexpected location", LOCATION_EXPECTED, req.params.location);
}
if (req.params.operationId !== OPERATION_ID_EXPECTED) {
throw new ValidationError("Unexpected operationId", OPERATION_ID_EXPECTED, req.params.operationId);
}
return {
status: 200,
body: json(validOperationStatus),
};
},
),
]);

Scenarios.Azure_ResourceManager_Models_Resources_OperationStatuses_getSubscriptionStatus = passOnSuccess([
mockapi.get(
"/subscriptions/:subscriptionId/providers/Azure.ResourceManager.Models.Resources/locations/:location/operationStatuses/:operationId",
(req) => {
req.expect.containsQueryParam("api-version", "2023-12-01-preview");
if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) {
throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId);
}
if (req.params.location !== LOCATION_EXPECTED) {
throw new ValidationError("Unexpected location", LOCATION_EXPECTED, req.params.location);
}
if (req.params.operationId !== OPERATION_ID_EXPECTED) {
throw new ValidationError("Unexpected operationId", OPERATION_ID_EXPECTED, req.params.operationId);
}
const resource = JSON.parse(JSON.stringify(validOperationStatus));
resource.name = "SubscriptionOperation";
return {
status: 200,
body: json(resource),
};
},
),
]);

Scenarios.Azure_ResourceManager_Models_Resources_OperationStatuses_getResourceGroupStatus = passOnSuccess([
mockapi.get(
"/subscriptions/:subscriptionId/resourceGroups/:resourceGroup/providers/Azure.ResourceManager.Models.Resources/locations/:location/operationStatuses/:operationId",
(req) => {
req.expect.containsQueryParam("api-version", "2023-12-01-preview");
if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) {
throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId);
}
if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) {
throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup);
}
if (req.params.location !== LOCATION_EXPECTED) {
throw new ValidationError("Unexpected location", LOCATION_EXPECTED, req.params.location);
}
if (req.params.operationId !== OPERATION_ID_EXPECTED) {
throw new ValidationError("Unexpected operationId", OPERATION_ID_EXPECTED, req.params.operationId);
}
const resource = JSON.parse(JSON.stringify(validOperationStatus));
resource.name = "ResourceGroupOperation";
return {
status: 200,
body: json(resource),
};
},
),
]);

// singleton tracked resource
Scenarios.Azure_ResourceManager_Models_Resources_SingletonTrackedResources_getByResourceGroup = passOnSuccess([
mockapi.get(
Expand Down

0 comments on commit ba3d4ac

Please sign in to comment.