2017-04-13 06:54:39 +03:00
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
// Licensed under the MIT License. See License.txt in the project root for license information.
|
|
|
|
|
2020-11-24 06:07:36 +03:00
|
|
|
import assert from "assert";
|
|
|
|
import * as utils from "../lib/util/utils";
|
2017-04-13 06:54:39 +03:00
|
|
|
|
2018-06-04 23:06:00 +03:00
|
|
|
describe("Utility functions", () => {
|
|
|
|
describe("Get Provider", () => {
|
|
|
|
it("should throw on empty", () => {
|
2017-04-13 09:49:14 +03:00
|
|
|
assert.throws(() => {
|
2020-11-24 06:07:36 +03:00
|
|
|
utils.getProvider("");
|
|
|
|
});
|
|
|
|
});
|
2018-06-04 23:06:00 +03:00
|
|
|
it("should throw null", () => {
|
2017-04-13 09:49:14 +03:00
|
|
|
assert.throws(() => {
|
2020-11-24 06:07:36 +03:00
|
|
|
utils.getProvider(null);
|
|
|
|
});
|
|
|
|
});
|
2018-06-04 23:06:00 +03:00
|
|
|
it("should throw undefined", () => {
|
2017-04-13 09:49:14 +03:00
|
|
|
assert.throws(() => {
|
2020-11-24 06:07:36 +03:00
|
|
|
utils.getProvider();
|
|
|
|
});
|
|
|
|
});
|
2018-06-04 23:06:00 +03:00
|
|
|
it("should return Microsoft.Resources", () => {
|
|
|
|
const path =
|
|
|
|
"/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/" +
|
2020-11-24 06:07:36 +03:00
|
|
|
"Microsoft.Resources/{parentResourcePath}/{resourceType}/{resourceName}";
|
|
|
|
const provider = utils.getProvider(path);
|
|
|
|
assert.strictEqual(provider, "Microsoft.Resources");
|
|
|
|
});
|
2018-06-04 23:06:00 +03:00
|
|
|
it("should return undefined", () => {
|
2020-11-24 06:07:36 +03:00
|
|
|
const path = "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/";
|
|
|
|
const provider = utils.getProvider(path);
|
|
|
|
assert.strictEqual(provider, undefined);
|
|
|
|
});
|
2018-06-04 23:06:00 +03:00
|
|
|
it("should return Microsoft.Authorization", () => {
|
|
|
|
const path =
|
|
|
|
"/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/" +
|
|
|
|
"Microsoft.Resources/{parentResourcePath}/{resourceType}/{resourceName}/providers/" +
|
2020-11-24 06:07:36 +03:00
|
|
|
"Microsoft.Authorization/roleAssignments";
|
|
|
|
const provider = utils.getProvider(path);
|
|
|
|
assert.strictEqual(provider, "Microsoft.Authorization");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|