Skip to content

Commit

Permalink
Reopen Tests ARM, test case for CheckNameAvailability operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
v-hongli1 committed Nov 5, 2024
1 parent 9680519 commit 51ef972
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 151 deletions.
105 changes: 52 additions & 53 deletions packages/cadl-ranch-specs/cadl-ranch-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,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 Expand Up @@ -1217,59 +1269,6 @@ Expected response body:
}
```

### Azure_ResourceManager_Resources_TopLevel_checkGlobalNameAvailability

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

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

```json
{
"name": "checkName",
"type": "global"
}
```

Expected response body:

```json
{
"nameAvailable": true,
"reason": "AlreadyExists",
"message": "This is a global name availability check message.."
}
```

### Azure_ResourceManager_Resources_TopLevel_checkLocalNameAvailability

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

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

```json
{
"name": "checkName",
"type": "local"
}
```

Expected response body:

```json
{
"nameAvailable": true,
"reason": "AlreadyExists",
"message": "This is a local name availability check message."
}
```

### Azure_ResourceManager_Resources_TopLevel_createOrReplace

- Endpoint: `put https://management.azure.com`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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.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,30 @@
import "@azure-tools/cadl-ranch-expect";
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 "./check-name-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,60 @@
import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";

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

const SUBSCRIPTION_ID_EXPECTED = "00000000-0000-0000-0000-000000000000";
const validCheckNameAvailability = {
nameAvailable: true,
reason: "AlreadyExists",
message: "",
};

// 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",
});
Original file line number Diff line number Diff line change
Expand Up @@ -61,57 +61,6 @@ const validSingletonResource = {
},
};

const validCheckNameAvailability = {
nameAvailable: true,
reason: "AlreadyExists",
message: "",
};

// Check Global Name Availability
Scenarios.Azure_ResourceManager_Resources_TopLevel_checkGlobalNameAvailability = passOnSuccess({
uri: "/subscriptions/:subscriptionId/providers/Azure.ResourceManager.Resources/checkNameAvailability",
method: "post",
request: {
params: {
"subscriptionId": SUBSCRIPTION_ID_EXPECTED,
"name": "checkName",
"type": "global",
"api-version": "2023-12-01-preview",
},
},
response: {
status: 200,
body: json({
...validCheckNameAvailability,
message: "This is a global name availability check message.",
}),
},
kind: "MockApiDefinition",
});

// Check Local Name Availability
Scenarios.Azure_ResourceManager_Resources_TopLevel_checkLocalNameAvailability = passOnSuccess({
uri: "/subscriptions/:subscriptionId/providers/Azure.ResourceManager.Resources/locations/:location/checkNameAvailability",
method: "post",
request: {
params: {
"subscriptionId": SUBSCRIPTION_ID_EXPECTED,
"location": "westus",
"name": "checkName",
"type": "local",
"api-version": "2023-12-01-preview",
},
},
response: {
status: 200,
body: json({
...validCheckNameAvailability,
message: "This is a global name availability check message.",
}),
},
kind: "MockApiDefinition",
});

// singleton tracked resource
Scenarios.Azure_ResourceManager_Resources_Singleton_getByResourceGroup = passOnSuccess({
uri: "/subscriptions/:subscriptionId/resourceGroups/:resourceGroup/providers/Azure.ResourceManager.Resources/singletonTrackedResources/default",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,51 +235,4 @@ interface TopLevel {
```
""")
actionSync is ArmResourceActionNoContentSync<TopLevelTrackedResource, NotificationDetails>;

@scenario
@scenarioDoc("""
Resource POST operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/providers/Azure.ResourceManager.Resources/checkNameAvailability
Expected query parameter: api-version=2023-12-01-preview
Expected request body:
```json
{
"name": "checkName",
"type": "global"
}
```
Expected response body:
```json
{
"nameAvailable": true,
"reason": "AlreadyExists",
"message": "This is a global name availability check message.."
}
```
""")
checkGlobalNameAvailability is checkGlobalNameAvailability;

@scenario
@scenarioDoc("""
Resource POST operation.
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/providers/Azure.ResourceManager.Resources/locations/westus/checkNameAvailability
Expected query parameter: api-version=2023-12-01-preview
Expected request body:
Expected request body:
```json
{
"name": "checkName",
"type": "local",
}
```
Expected response body:
```json
{
"nameAvailable": true,
"reason": "AlreadyExists",
"message": "This is a local name availability check message."
}
```
""")
checkLocalNameAvailability is checkLocalNameAvailability;
}

0 comments on commit 51ef972

Please sign in to comment.