-
Notifications
You must be signed in to change notification settings - Fork 393
Expand file tree
/
Copy pathupdateUID.test.ts
More file actions
110 lines (97 loc) · 5.6 KB
/
updateUID.test.ts
File metadata and controls
110 lines (97 loc) · 5.6 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
110
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import * as path from 'path';
import { devContainerDown, devContainerUp, shellExec } from './testUtils';
const pkg = require('../../package.json');
(process.platform === 'linux' ? describe.only : describe.skip)('Dev Containers CLI', function () {
this.timeout('120s');
const tmp = path.relative(process.cwd(), path.join(__dirname, 'tmp'));
const cli = `npx --prefix ${tmp} devcontainer`;
before('Install', async () => {
await shellExec(`rm -rf ${tmp}/node_modules`);
await shellExec(`mkdir -p ${tmp}`);
await shellExec(`npm --prefix ${tmp} install devcontainers-cli-${pkg.version}.tgz`);
});
describe('updateUID', () => {
it('should update UID and GID', async () => {
const testFolder = `${__dirname}/configs/updateUID`;
const containerId = (await devContainerUp(cli, testFolder)).containerId;
const uid = await shellExec(`${cli} exec --workspace-folder ${testFolder} id -u`);
assert.strictEqual(uid.stdout.trim(), String(process.getuid!()));
const gid = await shellExec(`${cli} exec --workspace-folder ${testFolder} id -g`);
assert.strictEqual(gid.stdout.trim(), String(process.getgid!()));
await devContainerDown({ containerId });
});
it('should update only UID when GID exists', async () => {
const testFolder = `${__dirname}/configs/updateUIDOnly`;
const containerId = (await devContainerUp(cli, testFolder, {
env: {
...process.env,
LOCAL_GID: String(process.getgid!())
}
})).containerId;
const uid = await shellExec(`${cli} exec --workspace-folder ${testFolder} id -u`);
assert.strictEqual(uid.stdout.trim(), String(process.getuid!()));
const gid = await shellExec(`${cli} exec --workspace-folder ${testFolder} id -g`);
assert.strictEqual(gid.stdout.trim(), String(4321));
await devContainerDown({ containerId });
});
it('should update UID and GID when the platform is linux/amd64', async () => {
const testFolder = `${__dirname}/configs/updateUIDamd64`;
const containerId = (await devContainerUp(cli, testFolder)).containerId;
const uid = await shellExec(`${cli} exec --workspace-folder ${testFolder} id -u`);
assert.strictEqual(uid.stdout.trim(), String(process.getuid!()));
const gid = await shellExec(`${cli} exec --workspace-folder ${testFolder} id -g`);
assert.strictEqual(gid.stdout.trim(), String(process.getgid!()));
await devContainerDown({ containerId });
});
it('should update UID and GID when --platform is linux/amd64', async () => {
const testFolder = `${__dirname}/configs/updateUIDamd64-platform-option`;
const containerId = (await devContainerUp(cli, testFolder)).containerId;
const uid = await shellExec(`${cli} exec --workspace-folder ${testFolder} id -u`);
assert.strictEqual(uid.stdout.trim(), String(process.getuid!()));
const gid = await shellExec(`${cli} exec --workspace-folder ${testFolder} id -g`);
assert.strictEqual(gid.stdout.trim(), String(process.getgid!()));
await devContainerDown({ containerId });
});
it('should update UID and GID when the platform is linux/arm64', async () => {
const testFolder = `${__dirname}/configs/updateUIDarm64`;
const containerId = (await devContainerUp(cli, testFolder)).containerId;
const uid = await shellExec(`${cli} exec --workspace-folder ${testFolder} id -u`);
assert.strictEqual(uid.stdout.trim(), String(process.getuid!()));
const gid = await shellExec(`${cli} exec --workspace-folder ${testFolder} id -g`);
assert.strictEqual(gid.stdout.trim(), String(process.getgid!()));
await devContainerDown({ containerId });
});
it('should update UID and GID when --platform is linux/arm64', async () => {
const testFolder = `${__dirname}/configs/updateUIDarm64-platform-option`;
const containerId = (await devContainerUp(cli, testFolder)).containerId;
const uid = await shellExec(`${cli} exec --workspace-folder ${testFolder} id -u`);
assert.strictEqual(uid.stdout.trim(), String(process.getuid!()));
const gid = await shellExec(`${cli} exec --workspace-folder ${testFolder} id -g`);
assert.strictEqual(gid.stdout.trim(), String(process.getgid!()));
await devContainerDown({ containerId });
});
it('should update UID and GID when the platform is linux/arm64/v8', async () => {
const testFolder = `${__dirname}/configs/updateUIDarm64v8`;
const containerId = (await devContainerUp(cli, testFolder)).containerId;
const uid = await shellExec(`${cli} exec --workspace-folder ${testFolder} id -u`);
assert.strictEqual(uid.stdout.trim(), String(process.getuid!()));
const gid = await shellExec(`${cli} exec --workspace-folder ${testFolder} id -g`);
assert.strictEqual(gid.stdout.trim(), String(process.getgid!()));
await devContainerDown({ containerId });
});
it('should update UID and GID when --platform is linux/arm64/v8', async () => {
const testFolder = `${__dirname}/configs/updateUIDarm64v8-platform-option`;
const containerId = (await devContainerUp(cli, testFolder)).containerId;
const uid = await shellExec(`${cli} exec --workspace-folder ${testFolder} id -u`);
assert.strictEqual(uid.stdout.trim(), String(process.getuid!()));
const gid = await shellExec(`${cli} exec --workspace-folder ${testFolder} id -g`);
assert.strictEqual(gid.stdout.trim(), String(process.getgid!()));
await devContainerDown({ containerId });
});
});
});