Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests ARM, test case for listing available operations #713

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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/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_getRgStatus

- 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_getStatus

- 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_OperationStatuses_getSubscriptionStatus
v-hongli1 marked this conversation as resolved.
Show resolved Hide resolved

- 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_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"
}]
}
}
```
""")
getStatus 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"
}]
}
}
```
""")
getRgStatus 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_getStatus = 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_getRgStatus = 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
Loading