-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathdeployContainerApp.test.ts
More file actions
109 lines (94 loc) · 5.58 KB
/
Copy pathdeployContainerApp.test.ts
File metadata and controls
109 lines (94 loc) · 5.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { type ManagedEnvironment } from '@azure/arm-appcontainers';
import { parseAzureResourceId } from '@microsoft/vscode-azext-azureutils';
import { IParsedError, parseError, randomUtils, runWithTestActionContext } from '@microsoft/vscode-azext-utils';
import * as assert from 'assert';
import * as path from 'path';
import { createContainerApp } from 'src/commands/createContainerApp/createContainerApp';
import { createManagedEnvironment } from 'src/commands/createManagedEnvironment/createManagedEnvironment';
import { deployContainerApp } from 'src/commands/deployContainerApp/deployContainerApp';
import { DeployWorkspaceProjectResults } from 'src/commands/deployWorkspaceProject/getDeployWorkspaceProjectResults';
import { ContainerAppItem } from 'src/tree/ContainerAppItem';
import { settingUtils } from 'src/utils/settingUtils';
import { workspace, type Uri, type WorkspaceFolder } from 'vscode';
import { longRunningTestsEnabled } from '../../global.test';
import { assertStringPropsMatch, getWorkspaceFolderUri } from '../../testUtils';
import { resourceGroupsToDelete } from '../global.nightly.test';
import { dwpTestUtils } from './dwpTestUtils';
suite('deployContainerApp.deployWorkspaceProject', async function (this: Mocha.Suite) {
this.timeout(15 * 60 * 1000);
suiteSetup(async function (this: Mocha.Context) {
if (!longRunningTestsEnabled) {
this.skip();
}
await settingUtils.updateGlobalSetting('groupBy', 'resourceType', 'azureResourceGroups');
});
test('should deploy properly from the container app item entry-point', async function () {
const containerAppItem = await createContainerAppItem();
const folderName: string = 'monorepo-admincreds';
const workspaceFolderUri: Uri = getWorkspaceFolderUri(folderName);
const rootFolder: WorkspaceFolder | undefined = workspace.getWorkspaceFolder(workspaceFolderUri);
assert.ok(rootFolder?.uri.fsPath, `Failed to find "${folderName}" root folder path.`);
const acrResourceName: string = 'dwpitemacr' + randomUtils.getRandomHexString(4);
const imageName: string = 'app1:latest';
const testInputs = [
'Workspace Project',
new RegExp(folderName, 'i'),
new RegExp('Create new container registry', 'i'),
acrResourceName,
'Standard',
'Docker Login Credentials',
'Enable',
path.join('app1', 'Dockerfile'),
`.${path.sep}app1`,
imageName,
path.join('app1', '.env.example'),
'Continue',
];
let results: DeployWorkspaceProjectResults = {};
await runWithTestActionContext('deployContainerApp.deployWorkspaceProject', async context => {
await context.ui.runWithInputs(testInputs, async () => {
try {
results = await deployContainerApp(context, containerAppItem) ?? {};
} catch (e) {
const perr: IParsedError = parseError(e);
console.error(perr.message);
}
});
});
const sharedResourcesName: string = parseAzureResourceId(containerAppItem.containerApp.managedEnvironmentId).resourceName;
const expectedResults = dwpTestUtils.generateExpectedResultsWithCredentials(sharedResourcesName, acrResourceName, containerAppItem.containerApp.name);
expectedResults.imageName = imageName;
// Verify `expectedResults`
assertStringPropsMatch(results as Partial<Record<string, string>>, expectedResults as Record<string, string | RegExp>, 'DeployContainerApp.DeployWorkspaceProject results mismatch.');
// Verify `postTestAssertion`
await runWithTestActionContext('deployContainerApp.deployWorkspaceProject.postTestAssertion', async context => {
const postTestAssertion = dwpTestUtils.generatePostTestAssertion({ targetPort: 3000, env: [{ name: 'MESSAGE', value: 'container apps (app1)' }] });
await postTestAssertion(context, results, 'DeployContainerApp.DeployWorkspaceProject resource settings mismatch.');
});
});
});
async function createContainerAppItem(): Promise<ContainerAppItem> {
let managedEnvironment: ManagedEnvironment | undefined;
await runWithTestActionContext('deployContainerApp.deployWorkspaceProject.createManagedEnvironment', async context => {
const resourceName: string = 'dwp-item' + randomUtils.getRandomHexString(4);
await context.ui.runWithInputs([resourceName, 'East US'], async () => {
managedEnvironment = await createManagedEnvironment(context);
});
});
let containerAppItem: ContainerAppItem | undefined;
await runWithTestActionContext('deployContainerApp.deployWorkspaceProject.createContainerApp', async context => {
const resourceName: string = 'dwp-item' + randomUtils.getRandomHexString(4);
await context.ui.runWithInputs([managedEnvironment?.name ?? '', resourceName], async () => {
containerAppItem = await createContainerApp(context);
});
});
if (managedEnvironment?.name) {
resourceGroupsToDelete.add(managedEnvironment.name);
}
assert.ok(containerAppItem, 'Failed to setup the starting container app item.');
return containerAppItem;
}