From b143889d3e2e615bf7e4c69d499bf6904847e560 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Tue, 15 Oct 2024 12:57:18 +0200 Subject: [PATCH] docker/install: Add tests for installing from image MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Gronowski --- __tests__/docker/install.test.itg.ts | 15 +++++------ __tests__/docker/install.test.ts | 39 ++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/__tests__/docker/install.test.itg.ts b/__tests__/docker/install.test.itg.ts index 911d758..c061afb 100644 --- a/__tests__/docker/install.test.itg.ts +++ b/__tests__/docker/install.test.itg.ts @@ -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'; @@ -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 @@ -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}}` diff --git a/__tests__/docker/install.test.ts b/__tests__/docker/install.test.ts index 28e2b5a..7016c56 100644 --- a/__tests__/docker/install.test.ts +++ b/__tests__/docker/install.test.ts @@ -21,7 +21,7 @@ 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-')); @@ -29,22 +29,39 @@ 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();