Skip to content

Commit 920ccb8

Browse files
authored
refactor: add arm e2e case (#9803)
* test: add arm test
1 parent f4d0f02 commit 920ccb8

File tree

6 files changed

+151
-1
lines changed

6 files changed

+151
-1
lines changed
File renamed without changes.
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"metadata": {
5+
"_generator": {
6+
"name": "bicep",
7+
"version": "0.4.451.19169",
8+
"templateHash": "17548000292248011536"
9+
}
10+
},
11+
"parameters": {
12+
"resourceBaseName": {
13+
"type": "string",
14+
"metadata": {
15+
"description": "Used to generate names for all resources in this file"
16+
},
17+
"minLength": 4,
18+
"maxLength": 25
19+
},
20+
"webAppSku": {
21+
"type": "string"
22+
},
23+
"serverfarmsName": {
24+
"type": "string",
25+
"defaultValue": "[parameters('resourceBaseName')]"
26+
},
27+
"location": {
28+
"type": "string",
29+
"defaultValue": "[resourceGroup().location]"
30+
}
31+
},
32+
"functions": [],
33+
"resources": [
34+
{
35+
"type": "Microsoft.Web/serverfarms",
36+
"apiVersion": "2021-02-01",
37+
"name": "[parameters('serverfarmsName')]",
38+
"kind": "app",
39+
"location": "[parameters('location')]",
40+
"sku": {
41+
"name": "[parameters('webAppSku')]"
42+
}
43+
}
44+
]
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"resourceBaseName": {
6+
"value": "tab${{RESOURCE_SUFFIX}}"
7+
},
8+
"webAppSku": {
9+
"value": "F1"
10+
}
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
/**
5+
* @author Zhaofeng Xu <[email protected]>
6+
*/
7+
8+
import { it } from "@microsoft/extra-shot-mocha";
9+
import { ProgrammingLanguage } from "@microsoft/teamsfx-core";
10+
import * as chai from "chai";
11+
import { describe } from "mocha";
12+
import * as path from "path";
13+
import { Cleaner } from "../../commonlib/cleaner";
14+
import { Capability } from "../../utils/constants";
15+
import {
16+
addJsonFileAndParamtersFile,
17+
updateYml,
18+
} from "../../utils/armDriverUtils";
19+
import { Executor } from "../../utils/executor";
20+
import { getTestFolder, getUniqueAppName } from "../commonUtils";
21+
22+
describe("version check", () => {
23+
const testFolder = getTestFolder();
24+
const appName = getUniqueAppName();
25+
const projectPath = path.resolve(testFolder, appName);
26+
27+
afterEach(async function () {
28+
await Cleaner.clean(projectPath);
29+
});
30+
31+
it(
32+
"arm json format and multiple deployment",
33+
{ testPlanCaseId: 16835373, author: "[email protected]" },
34+
async function () {
35+
{
36+
const result = await Executor.createProject(
37+
testFolder,
38+
appName,
39+
Capability.TabNonSso,
40+
ProgrammingLanguage.TS
41+
);
42+
chai.assert.isTrue(result.success);
43+
}
44+
await addJsonFileAndParamtersFile(projectPath);
45+
await updateYml(projectPath);
46+
{
47+
// provision
48+
const result = await Executor.provision(projectPath);
49+
chai.assert.isTrue(result.success);
50+
}
51+
}
52+
);
53+
});
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
import path from "path";
4+
import * as fs from "fs-extra";
5+
import { updateContent } from "./commonUtils";
6+
7+
const jsonFileName = "azure.json";
8+
const jsonParametersName = "azure.parameters.test.json";
9+
10+
export async function addJsonFileAndParamtersFile(
11+
projectPath: string
12+
): Promise<void> {
13+
const srcFolder = path.join(__dirname, "../../asset/armDriver");
14+
const destFolder = path.join(projectPath, "infra");
15+
await fs.copyFile(
16+
path.join(srcFolder, jsonFileName),
17+
path.join(destFolder, jsonFileName)
18+
);
19+
await fs.copyFile(
20+
path.join(srcFolder, jsonParametersName),
21+
path.join(destFolder, jsonParametersName)
22+
);
23+
}
24+
25+
export async function updateYml(projectPath: string): Promise<void> {
26+
const key = "deploymentName: Create-resources-for-tab";
27+
const replace = `
28+
- path: ./infra/azure.json
29+
parameters: ./infra/azure.parameters.test.json
30+
deploymentName: test-json-format
31+
`;
32+
const ymlPath = path.join(projectPath, "teamsapp.yml");
33+
let content = await fs.readFile(ymlPath, "utf-8");
34+
content = updateContent(content, key, replace);
35+
await fs.writeFileSync(ymlPath, content);
36+
}

packages/tests/src/utils/commonUtils.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,11 @@ export async function updateFunctionAuthorizationPolicy(
239239
await fs.writeFileSync(functionBicepPath, content);
240240
}
241241

242-
function updateContent(content: string, key: string, value: string): string {
242+
export function updateContent(
243+
content: string,
244+
key: string,
245+
value: string
246+
): string {
243247
const index = findNextEndLineIndexOfWord(content, key);
244248
const head = content.substring(0, index);
245249
const tail = content.substring(index + 1);

0 commit comments

Comments
 (0)