Skip to content

Commit

Permalink
docker/install: Add tests for installing from image
Browse files Browse the repository at this point in the history
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
  • Loading branch information
vvoland committed Oct 17, 2024
1 parent de390e0 commit b143889
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
15 changes: 7 additions & 8 deletions __tests__/docker/install.test.itg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import fs from 'fs';
import os from 'os';
import path from 'path';

import {Install} from '../../src/docker/install';
import {Install, InstallSourceArchive, InstallSourceImage} from '../../src/docker/install';
import {Docker} from '../../src/docker/docker';
import {Exec} from '../../src/exec';

Expand All @@ -40,8 +40,11 @@ aarch64:https://cloud.debian.org/images/cloud/bookworm/20231013-1532/debian-12-g
process.env = originalEnv;
});
// prettier-ignore
test.each(['v26.1.4'])(
'install docker %s', async (version) => {
test.each([
{type: 'archive', version: 'v26.1.4', channel: 'stable'} as InstallSourceArchive,
{type: 'image', tag: '27.3.1'} as InstallSourceImage,
])(
'install docker %s', async (source) => {
if (process.env.ImageOS && process.env.ImageOS.startsWith('ubuntu')) {
// Remove containerd first on ubuntu runners to make sure it takes
// ones packaged with docker
Expand All @@ -55,11 +58,7 @@ aarch64:https://cloud.debian.org/images/cloud/bookworm/20231013-1532/debian-12-g
}
await expect((async () => {
const install = new Install({
source: {
type: 'archive',
version: version,
channel: 'stable',
},
source: source,
runDir: tmpDir,
contextName: 'foo',
daemonConfig: `{"debug":true,"features":{"containerd-snapshotter":true}}`
Expand Down
39 changes: 28 additions & 11 deletions __tests__/docker/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,47 @@ import path from 'path';
import * as rimraf from 'rimraf';
import osm = require('os');

import {Install} from '../../src/docker/install';
import {Install, InstallSourceArchive, InstallSourceImage} from '../../src/docker/install';

const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'docker-install-'));

afterEach(function () {
rimraf.sync(tmpDir);
});

const archive = (version: string, channel: string): InstallSourceArchive => {
return {
type: 'archive',
version: version,
channel: channel
};
};

const image = (tag: string): InstallSourceImage => {
return {
type: 'image',
tag: tag
};
};

describe('download', () => {
// prettier-ignore
test.each([
['v19.03.14', 'linux'],
['v20.10.22', 'linux'],
['v20.10.22', 'darwin'],
['v20.10.22', 'win32'],
[archive('v19.03.14', 'stable'), 'linux'],
[archive('v20.10.22', 'stable'), 'linux'],
[archive('v20.10.22', 'stable'), 'darwin'],
[archive('v20.10.22', 'stable'), 'win32'],

[image('master'), 'linux'],
[image('master'), 'win32'],

[image('27.3.1'), 'linux'],
[image('27.3.1'), 'win32'],
])(
'acquires %p of docker (%s)', async (version, platformOS) => {
'acquires %p of docker (%s)', async (source, platformOS) => {
jest.spyOn(osm, 'platform').mockImplementation(() => platformOS as NodeJS.Platform);
const install = new Install({
source: {
type: 'archive',
version: version,
channel: 'stable',
},
source: source,
runDir: tmpDir,
});
const toolPath = await install.download();
Expand Down

0 comments on commit b143889

Please sign in to comment.