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

azure-http-specs, add ARM CheckNameAvailability operations case #1934

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 validCheckNameAvailability = {
v-hongli1 marked this conversation as resolved.
Show resolved Hide resolved
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(validCheckNameAvailability),
},
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(validCheckNameAvailability),
},
kind: "MockApiDefinition",
},
);

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