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_Resources_Nested_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
@@ -0,0 +1,29 @@
import "@typespec/http";
import "@typespec/rest";
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";

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

@armProviderNamespace
@service
@versioned(Versions)
@doc("Arm Resource Provider management API.")
namespace Azure.ResourceManager.OperationTemplates;

@doc("Azure API versions.")
enum Versions {
@armCommonTypesVersion(CommonTypes.Versions.v5)
@useDependency(Azure.Core.Versions.v1_0_Preview_2)
@useDependency(Azure.ResourceManager.Versions.v1_0_Preview_1)
@doc("Preview API version 2023-12-01-preview.")
v2023_12_01_preview: "2023-12-01-preview",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { json, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};

const SUBSCRIPTION_ID_EXPECTED = "00000000-0000-0000-0000-000000000000";
const validCheckNameAvailability = {
v-hongli1 marked this conversation as resolved.
Show resolved Hide resolved
nameAvailable: true,
reason: "AlreadyExists",
message: "",
};
v-hongli1 marked this conversation as resolved.
Show resolved Hide resolved

// 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,
message: "This is a global name availability check message.",
}),
},
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,
message: "This is a local name availability check message.",
}),
},
kind: "MockApiDefinition",
},
);
Loading