1
0
Fork 0
mirror of https://github.com/docker/setup-buildx-action.git synced 2025-04-22 16:06:36 +02:00

Add config-inline input

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2021-09-03 22:21:20 +02:00
parent ee7ac3140a
commit 34e94a5fed
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
13 changed files with 4751 additions and 16 deletions

View file

@ -6,6 +6,8 @@ import * as context from '../src/context';
import * as semver from 'semver';
import * as exec from '@actions/exec';
const tmpNameSync = path.join('/tmp/.docker-setup-buildx-jest', '.tmpname-jest').split(path.sep).join(path.posix.sep);
jest.spyOn(context, 'tmpDir').mockImplementation((): string => {
const tmpDir = path.join('/tmp/.docker-setup-buildx-jest').split(path.sep).join(path.posix.sep);
if (!fs.existsSync(tmpDir)) {
@ -14,6 +16,10 @@ jest.spyOn(context, 'tmpDir').mockImplementation((): string => {
return tmpDir;
});
jest.spyOn(context, 'tmpNameSync').mockImplementation((): string => {
return tmpNameSync;
});
describe('isAvailable', () => {
const execSpy: jest.SpyInstance = jest.spyOn(exec, 'getExecOutput');
buildx.isAvailable();
@ -119,3 +125,37 @@ describe('install', () => {
expect(fs.existsSync(buildxBin)).toBe(true);
}, 100000);
});
describe('getConfig', () => {
test.each([
['debug = true', false, 'debug = true', false],
[`notfound.toml`, true, '', true],
[
`${path.join(__dirname, 'fixtures', 'buildkitd.toml').split(path.sep).join(path.posix.sep)}`,
true,
`debug = true
[registry."docker.io"]
mirrors = ["mirror.gcr.io"]
`,
false
]
])('given %p config', async (val, file, exValue, invalid) => {
try {
let config: string;
if (file) {
config = await buildx.getConfigFile(val);
} else {
config = await buildx.getConfigInline(val);
}
expect(true).toBe(!invalid);
console.log(`config: ${config}`);
expect(config).toEqual(`${tmpNameSync}`);
const configValue = await fs.readFileSync(tmpNameSync, 'utf-8');
console.log(`configValue: ${configValue}`);
expect(configValue).toEqual(exValue);
} catch (err) {
console.log(err);
expect(true).toBe(invalid);
}
});
});

View file

@ -11,6 +11,10 @@ jest.spyOn(context, 'tmpDir').mockImplementation((): string => {
return tmpDir;
});
jest.spyOn(context, 'tmpNameSync').mockImplementation((): string => {
return path.join('/tmp/.docker-setup-buildx-jest', '.tmpname-jest').split(path.sep).join(path.posix.sep);
});
describe('getInputList', () => {
it('handles single line correctly', async () => {
await setInput('foo', 'bar');

View file

@ -0,0 +1,3 @@
debug = true
[registry."docker.io"]
mirrors = ["mirror.gcr.io"]