diff --git a/.changeset/fair-socks-add.md b/.changeset/fair-socks-add.md new file mode 100644 index 000000000..cbaeca9eb --- /dev/null +++ b/.changeset/fair-socks-add.md @@ -0,0 +1,5 @@ +--- +"@azure-tools/cadl-ranch-specs": patch +--- + +Added tests for ARM, test case for LocationResource. diff --git a/packages/cadl-ranch-specs/cadl-ranch-summary.md b/packages/cadl-ranch-specs/cadl-ranch-summary.md index 336e23b5a..1ff5a9b3c 100644 --- a/packages/cadl-ranch-specs/cadl-ranch-summary.md +++ b/packages/cadl-ranch-specs/cadl-ranch-summary.md @@ -907,6 +907,156 @@ Expected response body: } ``` +### Azure_ResourceManager_Models_Resources_LocationResources_createOrUpdate + +- 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": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "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": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "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": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "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": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } +} +``` + ### Azure_ResourceManager_Models_Resources_NestedProxyResources_createOrReplace - Endpoint: `put https://management.azure.com` diff --git a/packages/cadl-ranch-specs/http/azure/resource-manager/models/resources/location.tsp b/packages/cadl-ranch-specs/http/azure/resource-manager/models/resources/location.tsp new file mode 100644 index 000000000..35142e5cc --- /dev/null +++ b/packages/cadl-ranch-specs/http/azure/resource-manager/models/resources/location.tsp @@ -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 { + ...ResourceNameParameter; +} + +/** 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": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } + } + ``` + """) + get is ArmResourceRead; + + @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": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } + } + ``` + """) + createOrUpdate is ArmResourceCreateOrUpdateAsync; + + @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": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } + } + ``` + """) + update is ArmResourcePatchSync; + + @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; + + @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": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } + }] + } + ``` + """) + listByParent is ArmResourceListByParent; +} diff --git a/packages/cadl-ranch-specs/http/azure/resource-manager/models/resources/main.tsp b/packages/cadl-ranch-specs/http/azure/resource-manager/models/resources/main.tsp index bb2d8df67..52523d86d 100644 --- a/packages/cadl-ranch-specs/http/azure/resource-manager/models/resources/main.tsp +++ b/packages/cadl-ranch-specs/http/azure/resource-manager/models/resources/main.tsp @@ -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; diff --git a/packages/cadl-ranch-specs/http/azure/resource-manager/models/resources/mockapi.ts b/packages/cadl-ranch-specs/http/azure/resource-manager/models/resources/mockapi.ts index 011bd053a..b8271a257 100644 --- a/packages/cadl-ranch-specs/http/azure/resource-manager/models/resources/mockapi.ts +++ b/packages/cadl-ranch-specs/http/azure/resource-manager/models/resources/mockapi.ts @@ -5,6 +5,7 @@ export const Scenarios: Record = {}; const SUBSCRIPTION_ID_EXPECTED = "00000000-0000-0000-0000-000000000000"; const RESOURCE_GROUP_EXPECTED = "test-rg"; +const LOCATION_EXPECTED = "eastus"; const validTopLevelResource = { id: `/subscriptions/${SUBSCRIPTION_ID_EXPECTED}/resourceGroups/${RESOURCE_GROUP_EXPECTED}/providers/Azure.ResourceManager.Models.Resources/topLevelTrackedResources/top`, name: "top", @@ -61,6 +62,144 @@ const validSingletonResource = { }, }; +const validLocationResource = { + id: `/subscriptions/${SUBSCRIPTION_ID_EXPECTED}/locations/${LOCATION_EXPECTED}/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: new Date(), + lastModifiedBy: "AzureSDK", + lastModifiedAt: new Date(), + lastModifiedByType: "User", + }, +}; + +Scenarios.Azure_ResourceManager_Models_Resources_LocationResources_get = passOnSuccess([ + mockapi.get( + "/subscriptions/:subscriptionId/locations/:location/providers/Azure.ResourceManager.Models.Resources/locationResources/:locationResourceName", + (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.toLowerCase() !== LOCATION_EXPECTED) { + throw new ValidationError("Unexpected parent resource location", LOCATION_EXPECTED, req.params.location); + } + if (req.params.locationResourceName.toLowerCase() !== "resource") { + throw new ValidationError("Unexpected resource name", "resource", req.params.locationResourceName); + } + return { + status: 200, + body: json(validLocationResource), + }; + }, + ), +]); + +Scenarios.Azure_ResourceManager_Models_Resources_LocationResources_createOrUpdate = passOnSuccess([ + mockapi.put( + "/subscriptions/:subscriptionId/locations/:location/providers/Azure.ResourceManager.Models.Resources/locationResources/:locationResourceName", + (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.toLowerCase() !== LOCATION_EXPECTED) { + throw new ValidationError("Unexpected parent resource location", LOCATION_EXPECTED, req.params.location); + } + if (req.params.locationResourceName.toLowerCase() !== "resource") { + throw new ValidationError("Unexpected resource name", "resource", req.params.locationResourceName); + } + req.expect.bodyEquals({ + properties: { + description: "valid", + }, + }); + return { + status: 200, + body: json(validLocationResource), + }; + }, + ), +]); + +Scenarios.Azure_ResourceManager_Models_Resources_LocationResources_update = passOnSuccess([ + mockapi.patch( + "/subscriptions/:subscriptionId/locations/:location/providers/Azure.ResourceManager.Models.Resources/locationResources/:locationResourceName", + (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.toLowerCase() !== LOCATION_EXPECTED) { + throw new ValidationError("Unexpected parent resource location", LOCATION_EXPECTED, req.params.location); + } + if (req.params.locationResourceName.toLowerCase() !== "resource") { + throw new ValidationError("Unexpected resource name", "resource", req.params.locationResourceName); + } + req.expect.bodyEquals({ + properties: { + description: "valid2", + }, + }); + const resource = JSON.parse(JSON.stringify(validLocationResource)); + resource.properties.description = "valid2"; + return { + status: 200, + body: json(resource), + }; + }, + ), +]); + +Scenarios.Azure_ResourceManager_Models_Resources_LocationResources_delete = passOnSuccess([ + mockapi.delete( + "/subscriptions/:subscriptionId/locations/:location/providers/Azure.ResourceManager.Models.Resources/locationResources/:locationResourceName", + (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.toLowerCase() !== LOCATION_EXPECTED) { + throw new ValidationError("Unexpected parent resource location", LOCATION_EXPECTED, req.params.location); + } + if (req.params.locationResourceName.toLowerCase() !== "resource") { + throw new ValidationError("Unexpected resource name", "resource", req.params.locationResourceName); + } + return { + status: 204, + }; + }, + ), +]); + +Scenarios.Azure_ResourceManager_Models_Resources_LocationResources_listByParent = passOnSuccess([ + mockapi.get( + "/subscriptions/:subscriptionId/locations/:location/providers/Azure.ResourceManager.Models.Resources/locationResources", + (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.toLowerCase() !== LOCATION_EXPECTED) { + throw new ValidationError("Unexpected parent resource location", LOCATION_EXPECTED, req.params.location); + } + return { + status: 200, + body: json({ + value: [validLocationResource], + }), + }; + }, + ), +]); + // singleton tracked resource Scenarios.Azure_ResourceManager_Models_Resources_SingletonTrackedResources_getByResourceGroup = passOnSuccess([ mockapi.get(