Repository navigation
Expand file tree
/
Copy pathhelmfile.spec.ts
More file actions
79 lines (66 loc) · 2.74 KB
/
Copy pathhelmfile.spec.ts
File metadata and controls
79 lines (66 loc) · 2.74 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
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 { HelmfileInstallService } from './helmfile.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'),
}));
const baseUrl = 'https://github.com';
const tarball = 'helmfile archive';
describe('cli/tools/helmfile', () => {
beforeAll(async () => {
await ensurePaths(['tmp', 'opt/containerbase/bin']);
});
beforeEach(() => {
vi.mocked(arch).mockReturnValue('x64');
execaMock.mockResolvedValue({ failed: false });
});
test.each([
{ hostArch: 'x64', toolArch: 'amd64', version: '0.169.0' },
{ hostArch: 'arm64', toolArch: 'arm64', version: '0.169.1' },
] as const)(
'install on $toolArch',
async ({ hostArch, toolArch, version }) => {
vi.mocked(arch).mockReturnValue(hostArch);
const { svc, pathSvc } = await toolContext(HelmfileInstallService);
const filename = `helmfile_${version}_linux_${toolArch}.tar.gz`;
const releaseUrl = `/helmfile/helmfile/releases/download/v${version}`;
scope(baseUrl)
.get(`${releaseUrl}/helmfile_${version}_checksums.txt`)
.reply(200, `${checksum(tarball)} ${filename}\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: join(pathSvc.versionedToolPath('helmfile', version), 'bin'),
});
},
);
test('link', async () => {
const { svc, pathSvc } = await toolContext(HelmfileInstallService);
const spy = vi.spyOn(LinkToolService.prototype, 'shellwrapper');
await expect(svc.link('0.169.0')).resolves.toBeUndefined();
expect(spy).toHaveBeenCalledExactlyOnceWith('helmfile', {
srcDir: join(pathSvc.versionedToolPath('helmfile', '0.169.0'), 'bin'),
exports: 'HELMFILE_UPGRADE_NOTICE_DISABLED=1',
});
});
test('runs the tool test', async () => {
const { svc } = await toolContext(HelmfileInstallService);
await expect(svc.test('0.169.0')).resolves.toBeUndefined();
expect(execaMock).toHaveBeenCalledWith(
'helmfile',
['version'],
expect.any(Object),
);
});
});