Repository navigation
Expand file tree
/
Copy pathwally.spec.ts
More file actions
111 lines (95 loc) · 3.77 KB
/
Copy pathwally.spec.ts
File metadata and controls
111 lines (95 loc) · 3.77 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
111
import { arch } from 'node:os';
import { join } from 'node:path';
import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest';
import { CompressionService, LinkToolService } from '../services/index.ts';
import { getDistro, logger } from '../utils/index.ts';
import { WallyInstallService } from './wally.ts';
import { scope } from '~test/http-mock.ts';
import { ensurePaths } from '~test/path.ts';
import { checksum, toolContext } from '~test/tool.ts';
const { execaMock } = vi.hoisted(() => ({ execaMock: vi.fn() }));
vi.mock('execa', () => ({ execa: execaMock }));
vi.mock('node:os', async (importOriginal) => ({
...(await importOriginal<typeof import('node:os')>()),
arch: vi.fn(() => 'x64'),
}));
vi.mock('../utils/index.ts', async (importActual) => ({
...(await importActual<typeof import('../utils/index.ts')>()),
getDistro: vi.fn(),
}));
const baseUrl = 'https://github.com';
const tarball = 'wally archive';
describe('cli/tools/wally', () => {
beforeAll(async () => {
await ensurePaths(['tmp', 'opt/containerbase/bin']);
});
beforeEach(() => {
vi.mocked(arch).mockReturnValue('x64');
vi.mocked(getDistro).mockResolvedValue({
name: 'Ubuntu',
versionCode: 'jammy',
versionId: '22.04',
});
execaMock.mockResolvedValue({ failed: false });
});
test.each([
{ hostArch: 'x64', ghArch: 'x86_64', version: '0.3.2' },
{ hostArch: 'arm64', ghArch: 'aarch64', version: '0.3.3' },
] as const)('install on $ghArch', async ({ hostArch, ghArch, version }) => {
vi.mocked(arch).mockReturnValue(hostArch);
const { svc, pathSvc } = await toolContext(WallyInstallService);
const filename = `wally-${version}-jammy-${ghArch}.tar.xz`;
const releaseUrl = `/containerbase/wally-prebuild/releases/download/${version}`;
scope(baseUrl)
.get(`${releaseUrl}/${filename}.sha512`)
.reply(200, `${checksum(tarball, 'sha512')}\n`)
.get(`${releaseUrl}/${filename}`)
.reply(200, tarball);
const extract = vi.spyOn(CompressionService.prototype, 'extract');
await expect(svc.install(version)).resolves.toBeUndefined();
expect(extract).toHaveBeenCalledExactlyOnceWith({
file: expect.stringContaining(filename),
cwd: pathSvc.toolPath('wally'),
});
});
test.each([{ code: 'noble' }, { code: 'resolute' }])(
'install: uses the jammy prebuild on $code',
async ({ code }) => {
vi.mocked(getDistro).mockResolvedValue({
name: 'Ubuntu',
versionCode: code,
versionId: '24.04',
});
const version = `0.4.0-${code}`;
const { svc } = await toolContext(WallyInstallService);
const filename = `wally-${version}-jammy-x86_64.tar.xz`;
const releaseUrl = `/containerbase/wally-prebuild/releases/download/${version}`;
scope(baseUrl)
.get(`${releaseUrl}/${filename}.sha512`)
.reply(200, `${checksum(tarball, 'sha512')}\n`)
.get(`${releaseUrl}/${filename}`)
.reply(200, tarball);
await expect(svc.install(version)).resolves.toBeUndefined();
expect(logger.debug).toHaveBeenCalledWith(
`Using jammy prebuild for wally on ${code}`,
);
},
);
test('link', async () => {
const { svc, pathSvc } = await toolContext(WallyInstallService);
const spy = vi.spyOn(LinkToolService.prototype, 'shellwrapper');
await expect(svc.link('0.3.2')).resolves.toBeUndefined();
expect(spy).toHaveBeenCalledExactlyOnceWith('wally', {
srcDir: join(pathSvc.versionedToolPath('wally', '0.3.2'), 'bin'),
});
});
test('runs the tool test', async () => {
const { svc } = await toolContext(WallyInstallService);
await expect(svc.test('0.3.2')).resolves.toBeUndefined();
expect(execaMock).toHaveBeenCalledWith(
'wally',
['--version'],
expect.any(Object),
);
});
});