|
1 | 1 | import {beforeEach, describe, expect, jest, test} from '@jest/globals';
|
| 2 | +import * as fs from 'fs'; |
| 3 | +import * as path from 'path'; |
2 | 4 | import * as uuid from 'uuid';
|
3 | 5 | import {Buildx} from '@docker/actions-toolkit/lib/buildx/buildx';
|
| 6 | +import {Context} from '@docker/actions-toolkit/lib/context'; |
4 | 7 | import {Docker} from '@docker/actions-toolkit/lib/docker/docker';
|
5 | 8 | import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
6 | 9 | import {Node} from '@docker/actions-toolkit/lib/types/builder';
|
7 | 10 |
|
8 | 11 | import * as context from '../src/context';
|
9 | 12 |
|
| 13 | +const fixturesDir = path.join(__dirname, 'fixtures'); |
| 14 | +// prettier-ignore |
| 15 | +const tmpDir = path.join(process.env.TEMP || '/tmp', 'setup-buildx-jest'); |
| 16 | +const tmpName = path.join(tmpDir, '.tmpname-jest'); |
| 17 | + |
| 18 | +jest.spyOn(Context, 'tmpDir').mockImplementation((): string => { |
| 19 | + if (!fs.existsSync(tmpDir)) { |
| 20 | + fs.mkdirSync(tmpDir, {recursive: true}); |
| 21 | + } |
| 22 | + return tmpDir; |
| 23 | +}); |
| 24 | + |
| 25 | +jest.spyOn(Context, 'tmpName').mockImplementation((): string => { |
| 26 | + return tmpName; |
| 27 | +}); |
| 28 | + |
10 | 29 | jest.mock('uuid');
|
11 | 30 | jest.spyOn(uuid, 'v4').mockReturnValue('9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d');
|
12 | 31 |
|
@@ -171,6 +190,42 @@ describe('getCreateArgs', () => {
|
171 | 190 | '--name', 'builder-9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d',
|
172 | 191 | '--driver', 'unknown',
|
173 | 192 | ]
|
| 193 | + ], |
| 194 | + [ |
| 195 | + 8, |
| 196 | + 'v0.10.3', |
| 197 | + new Map<string, string>([ |
| 198 | + ['install', 'false'], |
| 199 | + ['use', 'false'], |
| 200 | + ['buildkitd-config', path.join(fixturesDir, 'buildkitd.toml')], |
| 201 | + ['cache-binary', 'true'], |
| 202 | + ['cleanup', 'true'], |
| 203 | + ]), |
| 204 | + [ |
| 205 | + 'create', |
| 206 | + '--name', 'builder-9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d', |
| 207 | + '--driver', 'docker-container', |
| 208 | + '--buildkitd-flags', '--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host', |
| 209 | + '--config', tmpName, |
| 210 | + ] |
| 211 | + ], |
| 212 | + [ |
| 213 | + 9, |
| 214 | + 'v0.10.3', |
| 215 | + new Map<string, string>([ |
| 216 | + ['install', 'false'], |
| 217 | + ['use', 'false'], |
| 218 | + ['buildkitd-config-inline', 'debug = true'], |
| 219 | + ['cache-binary', 'true'], |
| 220 | + ['cleanup', 'true'], |
| 221 | + ]), |
| 222 | + [ |
| 223 | + 'create', |
| 224 | + '--name', 'builder-9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d', |
| 225 | + '--driver', 'docker-container', |
| 226 | + '--buildkitd-flags', '--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host', |
| 227 | + '--config', tmpName, |
| 228 | + ] |
174 | 229 | ]
|
175 | 230 | ])(
|
176 | 231 | '[%d] given buildx %s and %p as inputs, returns %p',
|
|
0 commit comments