Skip to content

Commit

Permalink
[appplatform] Update appplatform projects to use snippets extraction (#…
Browse files Browse the repository at this point in the history
…32501)

### Packages impacted by this PR

- @azure/arm-appplatform

### Issues associated with this PR

- #32416

### Describe the problem that is addressed by this PR

Updates all `appplatform` projects to use snippets extraction.

### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?


### Are there test cases added in this PR? _(If not, why?)_


### Provide a list of related PRs _(if any)_


### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_

### Checklists
- [ ] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so,
create an Issue in the
[Autorest/typescript](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [ ] Added a changelog (if necessary)
  • Loading branch information
mpodwysocki authored Jan 10, 2025
1 parent d8fb4f6 commit 31d3d1c
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 73 deletions.
33 changes: 21 additions & 12 deletions sdk/appplatform/arm-appplatform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,28 @@ Set the values of the client ID, tenant ID, and client secret of the AAD applica

For more information about how to create an Azure AD Application check out [this guide](https://learn.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal).

```javascript
const { AppPlatformManagementClient } = require("@azure/arm-appplatform");
const { DefaultAzureCredential } = require("@azure/identity");
// For client-side applications running in the browser, use InteractiveBrowserCredential instead of DefaultAzureCredential. See https://aka.ms/azsdk/js/identity/examples for more details.
Using Node.js and Node-like environments, you can use the `DefaultAzureCredential` class to authenticate the client.

```ts snippet:ReadmeSampleCreateClient_Node
import { AppPlatformManagementClient } from "@azure/arm-appplatform";
import { DefaultAzureCredential } from "@azure/identity";

const subscriptionId = "00000000-0000-0000-0000-000000000000";
const client = new AppPlatformManagementClient(new DefaultAzureCredential(), subscriptionId);
```

For browser environments, use the `InteractiveBrowserCredential` from the `@azure/identity` package to authenticate.

// For client-side applications running in the browser, use this code instead:
// const credential = new InteractiveBrowserCredential({
// tenantId: "<YOUR_TENANT_ID>",
// clientId: "<YOUR_CLIENT_ID>"
// });
// const client = new AppPlatformManagementClient(credential, subscriptionId);
```ts snippet:ReadmeSampleCreateClient_Browser
import { InteractiveBrowserCredential } from "@azure/identity";
import { AppPlatformManagementClient } from "@azure/arm-appplatform";

const subscriptionId = "00000000-0000-0000-0000-000000000000";
const credential = new InteractiveBrowserCredential({
tenantId: "<YOUR_TENANT_ID>",
clientId: "<YOUR_CLIENT_ID>",
});
const client = new AppPlatformManagementClient(credential, subscriptionId);
```

### JavaScript Bundle
Expand All @@ -80,8 +88,9 @@ To use this client library in the browser, first you need to use a bundler. For

Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:

```javascript
const { setLogLevel } = require("@azure/logger");
```ts snippet:SetLogLevel
import { setLogLevel } from "@azure/logger";

setLogLevel("info");
```

Expand Down
26 changes: 12 additions & 14 deletions sdk/appplatform/arm-appplatform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@
"node": ">=18.0.0"
},
"dependencies": {
"@azure/abort-controller": "^1.0.0",
"@azure/core-auth": "^1.3.0",
"@azure/core-client": "^1.7.0",
"@azure/core-lro": "^2.5.4",
"@azure/core-paging": "^1.2.0",
"@azure/core-rest-pipeline": "^1.12.0",
"tslib": "^2.2.0"
"@azure/abort-controller": "^2.1.2",
"@azure/core-auth": "^1.9.0",
"@azure/core-client": "^1.9.2",
"@azure/core-lro": "^2.7.2",
"@azure/core-paging": "^1.6.2",
"@azure/core-rest-pipeline": "^1.18.1",
"tslib": "^2.8.1"
},
"keywords": [
"node",
"azure",
"typescript",
"browser",
"isomorphic"
"isomorphic",
"cloud"
],
"license": "MIT",
"main": "./dist/commonjs/index.js",
Expand All @@ -32,7 +33,7 @@
"@azure-tools/test-recorder": "^4.1.0",
"@azure-tools/test-utils-vitest": "^1.0.0",
"@azure/dev-tool": "^1.0.0",
"@azure/identity": "^4.0.1",
"@azure/identity": "^4.5.0",
"@types/node": "^18.0.0",
"@vitest/browser": "^2.1.8",
"@vitest/coverage-istanbul": "^2.1.8",
Expand All @@ -41,10 +42,7 @@
"typescript": "~5.7.2",
"vitest": "^2.1.8"
},
"repository": {
"type": "git",
"url": "https://github.com/Azure/azure-sdk-for-js.git"
},
"repository": "github:Azure/azure-sdk-for-js",
"bugs": {
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
},
Expand Down Expand Up @@ -79,7 +77,7 @@
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
"unit-test:browser": "echo skipped",
"unit-test:node": "dev-tool run test:vitest",
"update-snippets": "echo skipped"
"update-snippets": "dev-tool run update-snippets"
},
"sideEffects": false,
"//metadata": {
Expand Down
105 changes: 58 additions & 47 deletions sdk/appplatform/arm-appplatform/test/appplatform_examples.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/

import {
env,
Recorder,
RecorderStartOptions,
isPlaybackMode,
} from "@azure-tools/test-recorder";
import type { RecorderStartOptions } from "@azure-tools/test-recorder";
import { env, Recorder, isPlaybackMode } from "@azure-tools/test-recorder";
import { createTestCredential } from "@azure-tools/test-credential";
import { AppPlatformManagementClient } from "../src/appPlatformManagementClient.js";
import { afterEach, assert, beforeEach, describe, it } from "vitest";
Expand All @@ -20,7 +16,7 @@ const replaceableVariables: Record<string, string> = {
AZURE_CLIENT_ID: "azure_client_id",
AZURE_CLIENT_SECRET: "azure_client_secret",
AZURE_TENANT_ID: "88888888-8888-8888-8888-888888888888",
SUBSCRIPTION_ID: "azure_subscription_id"
SUBSCRIPTION_ID: "azure_subscription_id",
};

const recorderOptions: RecorderStartOptions = {
Expand All @@ -44,96 +40,111 @@ describe("AppPlatform test", () => {
let serviceName: string;
let appName: string;

beforeEach(async function (ctx) {
beforeEach(async (ctx) => {
recorder = new Recorder(ctx);
await recorder.start(recorderOptions);
subscriptionId = env.SUBSCRIPTION_ID || '';
subscriptionId = env.SUBSCRIPTION_ID || "";
// This is an example of how the environment variables are used
const credential = createTestCredential();
client = new AppPlatformManagementClient(credential, subscriptionId, recorder.configureClientOptions({}) as any);
client = new AppPlatformManagementClient(
credential,
subscriptionId,
recorder.configureClientOptions({}) as any,
);
location = "east us";
resourceGroup = "myjstest";
serviceName = "myservicexxx12";
appName = "myappxxx";
});

afterEach(async function () {
afterEach(async () => {
await recorder.stop();
});

it("services create test", async function () {
const res = await client.services.beginCreateOrUpdateAndWait(resourceGroup, serviceName, {
sku: {
name: "B0",
tier: "Basic"
},
tags: {
key1: "value1"
it("services create test", async () => {
const res = await client.services.beginCreateOrUpdateAndWait(
resourceGroup,
serviceName,
{
sku: {
name: "B0",
tier: "Basic",
},
tags: {
key1: "value1",
},
location: location,
},
location: location
}, testPollingOptions);
testPollingOptions,
);
assert.equal(res.name, serviceName);
});

it("apps create test", async function () {
const res = await client.apps.beginCreateOrUpdateAndWait(resourceGroup, serviceName, appName, {
properties: {
public: true,
// activeDeploymentName: "mydeployment1",
fqdn: "myapp.mydomain.com",
httpsOnly: false,
temporaryDisk: {
sizeInGB: 2,
mountPath: "/mytemporarydisk"
it("apps create test", async () => {
const res = await client.apps.beginCreateOrUpdateAndWait(
resourceGroup,
serviceName,
appName,
{
properties: {
public: true,
// activeDeploymentName: "mydeployment1",
fqdn: "myapp.mydomain.com",
httpsOnly: false,
temporaryDisk: {
sizeInGB: 2,
mountPath: "/mytemporarydisk",
},
persistentDisk: {
sizeInGB: 1,
mountPath: "/mypersistentdisk",
},
},
persistentDisk: {
sizeInGB: 1,
mountPath: "/mypersistentdisk"
}
}
}, testPollingOptions);
},
testPollingOptions,
);
assert.equal(res.name, appName);
});

it("services get test", async function () {
it("services get test", async () => {
const res = await client.services.get(resourceGroup, serviceName);
assert.equal(res.name, serviceName);
});

it("apps get test", async function () {
it("apps get test", async () => {
const res = await client.apps.get(resourceGroup, serviceName, appName);
assert.equal(res.name, appName);
});

it("apps list test", async function () {
it("apps list test", async () => {
const resArray = new Array();
for await (let item of client.apps.list(resourceGroup, serviceName)) {
for await (const item of client.apps.list(resourceGroup, serviceName)) {
resArray.push(item);
}
assert.equal(resArray.length, 1);
});

it("services list test", async function () {
it("services list test", async () => {
const resArray = new Array();
for await (let item of client.services.list(resourceGroup)) {
for await (const item of client.services.list(resourceGroup)) {
resArray.push(item);
}
assert.isTrue(resArray.length >= 1);
});

it("apps delete test", async function () {
it("apps delete test", async () => {
await client.apps.beginDeleteAndWait(resourceGroup, serviceName, appName, testPollingOptions);
const resArray = new Array();
for await (let item of client.apps.list(resourceGroup, serviceName)) {
for await (const item of client.apps.list(resourceGroup, serviceName)) {
resArray.push(item);
}
assert.equal(resArray.length, 0);
});

it("services delete test", async function () {
it("services delete test", async () => {
await client.services.beginDeleteAndWait(resourceGroup, serviceName, testPollingOptions);
const resArray = new Array();
for await (let item of client.services.list(resourceGroup)) {
for await (const item of client.services.list(resourceGroup)) {
resArray.push(item);
}
assert.equal(resArray.length, 0);
Expand Down
27 changes: 27 additions & 0 deletions sdk/appplatform/arm-appplatform/test/snippets.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { AppPlatformManagementClient } from "@azure/arm-appplatform";
import { DefaultAzureCredential, InteractiveBrowserCredential } from "@azure/identity";
import { setLogLevel } from "@azure/logger";
import { describe, it } from "vitest";

describe("snippets", () => {
it("ReadmeSampleCreateClient_Node", async () => {
const subscriptionId = "00000000-0000-0000-0000-000000000000";
const client = new AppPlatformManagementClient(new DefaultAzureCredential(), subscriptionId);
});

it("ReadmeSampleCreateClient_Browser", async () => {
const subscriptionId = "00000000-0000-0000-0000-000000000000";
const credential = new InteractiveBrowserCredential({
tenantId: "<YOUR_TENANT_ID>",
clientId: "<YOUR_CLIENT_ID>",
});
const client = new AppPlatformManagementClient(credential, subscriptionId);
});

it("SetLogLevel", async () => {
setLogLevel("info");
});
});

0 comments on commit 31d3d1c

Please sign in to comment.