|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import * as assert from 'assert'; |
| 7 | +import * as path from 'path'; |
| 8 | +import { devContainerDown, devContainerUp, shellExec } from './testUtils'; |
| 9 | + |
| 10 | +const pkg = require('../../package.json'); |
| 11 | + |
| 12 | +(process.platform === 'linux' ? describe : describe.skip)('Dev Containers CLI', function () { |
| 13 | + this.timeout('120s'); |
| 14 | + |
| 15 | + const tmp = path.relative(process.cwd(), path.join(__dirname, 'tmp')); |
| 16 | + const cli = `npx --prefix ${tmp} devcontainer`; |
| 17 | + |
| 18 | + before('Install', async () => { |
| 19 | + await shellExec(`rm -rf ${tmp}/node_modules`); |
| 20 | + await shellExec(`mkdir -p ${tmp}`); |
| 21 | + await shellExec(`npm --prefix ${tmp} install devcontainers-cli-${pkg.version}.tgz`); |
| 22 | + }); |
| 23 | + |
| 24 | + describe('updateUID', () => { |
| 25 | + it('should update UID and GID', async () => { |
| 26 | + const testFolder = `${__dirname}/configs/updateUID`; |
| 27 | + const containerId = (await devContainerUp(cli, testFolder)).containerId; |
| 28 | + const uid = await shellExec(`${cli} exec --workspace-folder ${testFolder} id -u`); |
| 29 | + assert.strictEqual(uid.stdout.trim(), String(process.getuid!())); |
| 30 | + const gid = await shellExec(`${cli} exec --workspace-folder ${testFolder} id -g`); |
| 31 | + assert.strictEqual(gid.stdout.trim(), String(process.getgid!())); |
| 32 | + await devContainerDown({ containerId }); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should update only UID when GID exists', async () => { |
| 36 | + const testFolder = `${__dirname}/configs/updateUIDOnly`; |
| 37 | + const containerId = (await devContainerUp(cli, testFolder, { |
| 38 | + env: { |
| 39 | + ...process.env, |
| 40 | + LOCAL_GID: String(process.getgid!()) |
| 41 | + } |
| 42 | + })).containerId; |
| 43 | + const uid = await shellExec(`${cli} exec --workspace-folder ${testFolder} id -u`); |
| 44 | + assert.strictEqual(uid.stdout.trim(), String(process.getuid!())); |
| 45 | + const gid = await shellExec(`${cli} exec --workspace-folder ${testFolder} id -g`); |
| 46 | + assert.strictEqual(gid.stdout.trim(), String(4321)); |
| 47 | + await devContainerDown({ containerId }); |
| 48 | + }); |
| 49 | + }); |
| 50 | +}); |
0 commit comments