botbook/node_modules/@azure/arm-resources/dist-esm/test/resources_examples.js

212 lines
8.2 KiB
JavaScript
Raw Normal View History

2024-09-04 13:13:15 -03:00
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
import { __asyncValues, __awaiter } from "tslib";
import { env, Recorder, isPlaybackMode, } from "@azure-tools/test-recorder";
import { createTestCredential } from "@azure-tools/test-credential";
import { assert } from "chai";
import { ResourceManagementClient } from "../src/resourceManagementClient";
const replaceableVariables = {
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"
};
const recorderOptions = {
envSetupForPlayback: replaceableVariables
};
export const testPollingOptions = {
updateIntervalInMs: isPlaybackMode() ? 0 : undefined,
};
describe("Resources test", () => {
let recorder;
let subscriptionId;
let client;
let location;
let resourceGroup;
let tagName;
let scope;
beforeEach(function () {
return __awaiter(this, void 0, void 0, function* () {
recorder = new Recorder(this.currentTest);
yield recorder.start(recorderOptions);
subscriptionId = env.SUBSCRIPTION_ID || '';
// This is an example of how the environment variables are used
const credential = createTestCredential();
client = new ResourceManagementClient(credential, subscriptionId, recorder.configureClientOptions({}));
location = "eastus";
resourceGroup = "myjstest1";
tagName = "tagyyy";
scope = "subscriptions/" + subscriptionId + "/resourcegroups/" + resourceGroup;
});
});
afterEach(function () {
return __awaiter(this, void 0, void 0, function* () {
yield recorder.stop();
});
});
it("resourceGroups create test", function () {
return __awaiter(this, void 0, void 0, function* () {
const res = yield client.resourceGroups.createOrUpdate(resourceGroup, {
location: location,
tags: {
tag1: "value1"
}
});
assert.equal(res.name, resourceGroup);
});
});
it("resourceGroups get test", function () {
return __awaiter(this, void 0, void 0, function* () {
const res = yield client.resourceGroups.get(resourceGroup);
assert.equal(res.name, resourceGroup);
});
});
it("resourceGroups list test", function () {
var e_1, _a;
return __awaiter(this, void 0, void 0, function* () {
const resArray = new Array();
try {
for (var _b = __asyncValues(client.resourceGroups.list()), _c; _c = yield _b.next(), !_c.done;) {
let item = _c.value;
resArray.push(item);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
assert.notEqual(resArray.length, 0);
});
});
it("resourceGroups update test", function () {
return __awaiter(this, void 0, void 0, function* () {
const res = yield client.resourceGroups.update(resourceGroup, {
tags: {
tag1: "value1",
tag2: "value2"
}
});
assert.equal(res.type, "Microsoft.Resources/resourceGroups");
});
});
it("tagsOperations create test", function () {
return __awaiter(this, void 0, void 0, function* () {
const res = yield client.tagsOperations.createOrUpdate(tagName);
assert.equal(res.tagName, tagName);
});
});
it("tagsOperations get test", function () {
return __awaiter(this, void 0, void 0, function* () {
const res = yield client.tagsOperations.getAtScope(scope);
assert.equal(res.name, "default");
});
});
it("tagsOperations list test", function () {
var e_2, _a;
return __awaiter(this, void 0, void 0, function* () {
const resArray = new Array();
try {
for (var _b = __asyncValues(client.tagsOperations.list()), _c; _c = yield _b.next(), !_c.done;) {
let item = _c.value;
resArray.push(item);
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
}
finally { if (e_2) throw e_2.error; }
}
assert.notEqual(resArray.length, 0);
});
});
it("tagsOperations update test", function () {
return __awaiter(this, void 0, void 0, function* () {
const res = yield client.tagsOperations.updateAtScope(scope, {
operation: "Delete",
properties: {
tags: {
tagkey1: "tagvalue1"
}
}
});
assert.equal(res.type, "Microsoft.Resources/tags");
});
});
it("tagsOperations delete test", function () {
var e_3, _a;
return __awaiter(this, void 0, void 0, function* () {
const res = yield client.tagsOperations.deleteAtScope(scope);
const resArray = new Array();
try {
for (var _b = __asyncValues(client.tagsOperations.list()), _c; _c = yield _b.next(), !_c.done;) {
let item = _c.value;
resArray.push(item);
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
}
finally { if (e_3) throw e_3.error; }
}
assert.equal(resArray.length, 24);
});
});
it("resourceGroups delete test", function () {
var e_4, _a;
return __awaiter(this, void 0, void 0, function* () {
const res = yield client.resourceGroups.beginDeleteAndWait(resourceGroup, testPollingOptions);
const resArray = new Array();
try {
for (var _b = __asyncValues(client.resourceGroups.list()), _c; _c = yield _b.next(), !_c.done;) {
let item = _c.value;
resArray.push(item);
}
}
catch (e_4_1) { e_4 = { error: e_4_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
}
finally { if (e_4) throw e_4.error; }
}
assert.notEqual(resArray.length, 0);
});
});
it("resources list test", function () {
var e_5, _a;
return __awaiter(this, void 0, void 0, function* () {
const filter = `ResourceType eq 'Microsoft.OperationsManagement/solutions'`;
const resources = [];
const resourcesIterable = client.resources.list({ filter, top: 1 });
try {
// const resourcesIterable = resourceManager.resources.list();
for (var resourcesIterable_1 = __asyncValues(resourcesIterable), resourcesIterable_1_1; resourcesIterable_1_1 = yield resourcesIterable_1.next(), !resourcesIterable_1_1.done;) {
const resource = resourcesIterable_1_1.value;
resources.push(resource);
}
}
catch (e_5_1) { e_5 = { error: e_5_1 }; }
finally {
try {
if (resourcesIterable_1_1 && !resourcesIterable_1_1.done && (_a = resourcesIterable_1.return)) yield _a.call(resourcesIterable_1);
}
finally { if (e_5) throw e_5.error; }
}
;
assert(resources.length > 1);
});
});
});
//# sourceMappingURL=resources_examples.js.map