Test ARM, test case for SingletonResource (#702)

* Test ARM, test case for SingletonResource
This commit is contained in:
Hong Li(MSFT) 2024-08-27 09:31:07 +08:00 коммит произвёл GitHub
Родитель cd9fdd66e6
Коммит 8f431084ba
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
5 изменённых файлов: 433 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,5 @@
---
"@azure-tools/cadl-ranch-specs": patch
---
Added tests for ARM, test case for SingletonResource.

Просмотреть файл

@ -1056,6 +1056,152 @@ Expected response body:
}
```
### Azure_ResourceManager_Models_Resources_SingletonTrackedResources_createOrUpdate
- Endpoint: `put https://management.azure.com`
Resource PUT operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Models.Resources/singletonTrackedResources/default
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.ResourceManager.Models.Resources/singletonTrackedResources/default",
"name": "default",
"type": "Azure.ResourceManager.Models.Resources/singletonTrackedResources",
"location": "eastus",
"properties": {
"description": "valid",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}
```
### Azure_ResourceManager_Models_Resources_SingletonTrackedResources_getByResourceGroup
- 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/singletonTrackedResources/default
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.ResourceManager.Models.Resources/singletonTrackedResources/default",
"name": "default",
"type": "Azure.ResourceManager.Models.Resources/singletonTrackedResources",
"location": "eastus",
"properties":{
"description": "valid",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}
```
### Azure_ResourceManager_Models_Resources_SingletonTrackedResources_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.ResourceManager.Models.Resources/singletonTrackedResources
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.ResourceManager.Models.Resources/singletonTrackedResources/default",
"name": "default",
"type": "Azure.ResourceManager.Models.Resources/singletonTrackedResources",
"location": "eastus",
"properties":{
"description": "valid",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}]
}
```
### Azure_ResourceManager_Models_Resources_SingletonTrackedResources_update
- Endpoint: `patch https://management.azure.com`
Resource PATCH operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Models.Resources/singletonTrackedResources/default
Expected query parameter: api-version=2023-12-01-preview
Expected request body:
```json
{
"location": "eastus2",
"properties": {
"description": "valid2"
}
}
```
Expected response body:
```json
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Models.Resources/singletonTrackedResources/default",
"name": "default",
"type": "Azure.ResourceManager.Models.Resources/singletonTrackedResources",
"location": "eastus2",
"properties":{
"description": "valid2",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}
```
### Azure_ResourceManager_Models_Resources_TopLevelTrackedResources_actionSync
- Endpoint: `post https://management.azure.com`

Просмотреть файл

@ -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 "./singleton.tsp";
using TypeSpec.Http;
using TypeSpec.Rest;

Просмотреть файл

@ -42,6 +42,119 @@ const validNestedResource = {
},
};
const validSingletonResource = {
id: `/subscriptions/${SUBSCRIPTION_ID_EXPECTED}/resourceGroups/${RESOURCE_GROUP_EXPECTED}/providers/Azure.ResourceManager.Models.Resources/singletonTrackedResources/default`,
name: "default",
type: "Azure.ResourceManager.Models.Resources/singletonTrackedResources",
location: "eastus",
properties: {
provisioningState: "Succeeded",
description: "valid",
},
systemData: {
createdBy: "AzureSDK",
createdByType: "User",
createdAt: new Date(),
lastModifiedBy: "AzureSDK",
lastModifiedAt: new Date(),
lastModifiedByType: "User",
},
};
// singleton tracked resource
Scenarios.Azure_ResourceManager_Models_Resources_SingletonTrackedResources_getByResourceGroup = passOnSuccess([
mockapi.get(
"/subscriptions/:subscriptionId/resourceGroups/:resourceGroup/providers/Azure.ResourceManager.Models.Resources/singletonTrackedResources/default",
(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);
}
return {
status: 200,
body: json(validSingletonResource),
};
},
),
]);
Scenarios.Azure_ResourceManager_Models_Resources_SingletonTrackedResources_createOrUpdate = passOnSuccess([
mockapi.put(
"/subscriptions/:subscriptionId/resourceGroups/:resourceGroup/providers/Azure.ResourceManager.Models.Resources/singletonTrackedResources/default",
(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);
}
req.expect.bodyEquals({
location: "eastus",
properties: {
description: "valid",
},
});
return {
status: 200,
body: json(validSingletonResource),
};
},
),
]);
Scenarios.Azure_ResourceManager_Models_Resources_SingletonTrackedResources_update = passOnSuccess([
mockapi.patch(
"/subscriptions/:subscriptionId/resourceGroups/:resourceGroup/providers/Azure.ResourceManager.Models.Resources/singletonTrackedResources/default",
(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);
}
req.expect.bodyEquals({
location: "eastus2",
properties: {
description: "valid2",
},
});
const resource = JSON.parse(JSON.stringify(validSingletonResource));
resource.location = "eastus2";
resource.properties.description = "valid2";
return {
status: 200,
body: json(resource),
};
},
),
]);
Scenarios.Azure_ResourceManager_Models_Resources_SingletonTrackedResources_listByResourceGroup = passOnSuccess([
mockapi.get(
"/subscriptions/:subscriptionId/resourceGroups/:resourceGroup/providers/Azure.ResourceManager.Models.Resources/singletonTrackedResources",
(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);
}
return {
status: 200,
body: json({
value: [validSingletonResource],
}),
};
},
),
]);
Scenarios.Azure_ResourceManager_Models_Resources_TopLevelTrackedResources_actionSync = passOnSuccess([
mockapi.post(
"/subscriptions/:subscriptionId/resourceGroups/:resourceGroup/providers/Azure.ResourceManager.Models.Resources/topLevelTrackedResources/:topLevelResourceName/actionSync",

Просмотреть файл

@ -0,0 +1,168 @@
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;
@singleton("default")
model SingletonTrackedResource is TrackedResource<SingletonTrackedResourceProperties> {
...ResourceNameParameter<SingletonTrackedResource>;
}
@doc("Singleton Arm Resource Properties.")
model SingletonTrackedResourceProperties {
@visibility("read")
@doc("The status of the last operation.")
provisioningState?: ProvisioningState;
@doc("The description of the resource.")
description?: string;
}
@armResourceOperations
interface SingletonTrackedResources {
@scenario
@scenarioDoc("""
Resource GET operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Models.Resources/singletonTrackedResources/default
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.ResourceManager.Models.Resources/singletonTrackedResources/default",
"name": "default",
"type": "Azure.ResourceManager.Models.Resources/singletonTrackedResources",
"location": "eastus",
"properties":{
"description": "valid",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}
```
""")
getByResourceGroup is ArmResourceRead<SingletonTrackedResource>;
@scenario
@scenarioDoc("""
Resource PUT operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Models.Resources/singletonTrackedResources/default
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.ResourceManager.Models.Resources/singletonTrackedResources/default",
"name": "default",
"type": "Azure.ResourceManager.Models.Resources/singletonTrackedResources",
"location": "eastus",
"properties": {
"description": "valid",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}
```
""")
createOrUpdate is ArmResourceCreateOrReplaceAsync<SingletonTrackedResource>;
@scenario
@scenarioDoc("""
Resource PATCH operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Models.Resources/singletonTrackedResources/default
Expected query parameter: api-version=2023-12-01-preview
Expected request body:
```json
{
"location": "eastus2",
"properties": {
"description": "valid2"
}
}
```
Expected response body:
```json
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Models.Resources/singletonTrackedResources/default",
"name": "default",
"type": "Azure.ResourceManager.Models.Resources/singletonTrackedResources",
"location": "eastus2",
"properties":{
"description": "valid2",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}
```
""")
update is ArmResourcePatchSync<SingletonTrackedResource, SingletonTrackedResourceProperties>;
@scenario
@scenarioDoc("""
Resource LIST by resource group operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Models.Resources/singletonTrackedResources
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.ResourceManager.Models.Resources/singletonTrackedResources/default",
"name": "default",
"type": "Azure.ResourceManager.Models.Resources/singletonTrackedResources",
"location": "eastus",
"properties":{
"description": "valid",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}]
}
```
""")
listByResourceGroup is ArmResourceListByParent<SingletonTrackedResource>;
}