Skip to content

Commit

Permalink
azure-http-specs, add ARM CheckNameAvailability operations case (#1934)
Browse files Browse the repository at this point in the history
### Context

- fix Azure/cadl-ranch#680
- not covering legacy cases
  • Loading branch information
v-hongli1 authored Dec 25, 2024
1 parent f6ee7bb commit 72b4cfb
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@azure-tools/azure-http-specs"
---

Added CheckNameAvailability operations case for ARM tests.
52 changes: 52 additions & 0 deletions packages/azure-http-specs/spec-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,58 @@ Expected response body:
}
```

### Azure_ResourceManager_OperationTemplates_CheckNameAvailability_checkGlobal

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

Resource POST operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/providers/Azure.ResourceManager.OperationTemplates/checkNameAvailability
Expected query parameter: api-version=2023-12-01-preview
Expected request body:

```json
{
"name": "checkName",
"type": "Microsoft.Web/site"
}
```

Expected response body:

```json
{
"nameAvailable": false,
"reason": "AlreadyExists",
"message": "Hostname 'checkName' already exists. Please select a different name."
}
```

### Azure_ResourceManager_OperationTemplates_CheckNameAvailability_checkLocal

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

Resource POST operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/providers/Azure.ResourceManager.OperationTemplates/locations/westus/checkNameAvailability
Expected query parameter: api-version=2023-12-01-preview
Expected request body:

```json
{
"name": "checkName",
"type": "Microsoft.Web/site"
}
```

Expected response body:

```json
{
"nameAvailable": false,
"reason": "AlreadyExists",
"message": "Hostname 'checkName' already exists. Please select a different name."
}
```

### Azure_ResourceManager_OperationTemplates_Lro_createOrReplace

- Endpoint: `put https://management.azure.com`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import "@typespec/http";
import "@typespec/rest";
import "@azure-tools/typespec-azure-core";
import "@azure-tools/typespec-azure-resource-manager";
import "@typespec/spector";

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

namespace Azure.ResourceManager.OperationTemplates;

interface CheckNameAvailability {
@scenario
@scenarioDoc("""
Resource POST operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/providers/Azure.ResourceManager.OperationTemplates/checkNameAvailability
Expected query parameter: api-version=2023-12-01-preview
Expected request body:
```json
{
"name": "checkName",
"type": "Microsoft.Web/site"
}
```
Expected response body:
```json
{
"nameAvailable": false,
"reason": "AlreadyExists",
"message": "Hostname 'checkName' already exists. Please select a different name."
}
```
""")
checkGlobal is checkGlobalNameAvailability;

@scenario
@scenarioDoc("""
Resource POST operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/providers/Azure.ResourceManager.OperationTemplates/locations/westus/checkNameAvailability
Expected query parameter: api-version=2023-12-01-preview
Expected request body:
```json
{
"name": "checkName",
"type": "Microsoft.Web/site",
}
```
Expected response body:
```json
{
"nameAvailable": false,
"reason": "AlreadyExists",
"message": "Hostname 'checkName' already exists. Please select a different name."
}
```
""")
checkLocal is checkLocalNameAvailability;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "@typespec/versioning";
import "@azure-tools/typespec-azure-core";
import "@azure-tools/typespec-azure-resource-manager";
import "@azure-tools/typespec-client-generator-core";
import "./checkname-availability.tsp";
import "./lro.tsp";

using TypeSpec.Http;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,61 @@ const validOrder = {
lastModifiedByType: "User",
},
};
const checkNameAvailabilityResponse = {
nameAvailable: false,
reason: "AlreadyExists",
message: "Hostname 'checkName' already exists. Please select a different name.",
};
let createOrReplacePollCount = 0;
let postPollCount = 0;
let deletePollCount = 0;

// Check Global Name Availability
Scenarios.Azure_ResourceManager_OperationTemplates_CheckNameAvailability_checkGlobal =
passOnSuccess({
uri: "/subscriptions/:subscriptionId/providers/Azure.ResourceManager.OperationTemplates/checkNameAvailability",
method: "post",
request: {
params: {
subscriptionId: SUBSCRIPTION_ID_EXPECTED,
"api-version": "2023-12-01-preview",
},
body: {
name: "checkName",
type: "Microsoft.Web/site",
},
},
response: {
status: 200,
body: json(checkNameAvailabilityResponse),
},
kind: "MockApiDefinition",
});

// Check Local Name Availability
Scenarios.Azure_ResourceManager_OperationTemplates_CheckNameAvailability_checkLocal = passOnSuccess(
{
uri: "/subscriptions/:subscriptionId/providers/Azure.ResourceManager.OperationTemplates/locations/:location/checkNameAvailability",
method: "post",
request: {
params: {
subscriptionId: SUBSCRIPTION_ID_EXPECTED,
location: "westus",
"api-version": "2023-12-01-preview",
},
body: {
name: "checkName",
type: "Microsoft.Web/site",
},
},
response: {
status: 200,
body: json(checkNameAvailabilityResponse),
},
kind: "MockApiDefinition",
},
);

// lro resource
Scenarios.Azure_ResourceManager_OperationTemplates_Lro_createOrReplace = passOnSuccess([
{
Expand Down

0 comments on commit 72b4cfb

Please sign in to comment.