|
1 | 1 | import * as fs from 'fs'; |
2 | 2 | import * as path from 'path'; |
3 | 3 | import * as semver from 'semver'; |
| 4 | + |
4 | 5 | import * as buildx from '../src/buildx'; |
5 | | -import * as docker from '../src/docker'; |
6 | 6 | import * as context from '../src/context'; |
| 7 | +import * as docker from '../src/docker'; |
7 | 8 |
|
8 | 9 | const tmpNameSync = path.join('/tmp/.docker-build-push-jest', '.tmpname-jest').split(path.sep).join(path.posix.sep); |
9 | 10 | const digest = 'sha256:bfb45ab72e46908183546477a08f8867fc40cebadd00af54b071b097aed127a9'; |
@@ -118,15 +119,23 @@ describe('parseVersion', () => { |
118 | 119 |
|
119 | 120 | describe('getSecret', () => { |
120 | 121 | test.each([ |
121 | | - ['A_SECRET', 'abcdef0123456789'], |
122 | | - ['GIT_AUTH_TOKEN', 'abcdefghijklmno=0123456789'], |
123 | | - ['MY_KEY', 'c3RyaW5nLXdpdGgtZXF1YWxzCg=='] |
124 | | - ])('given %p key and %p secret', async (key, secret) => { |
125 | | - const secretArgs = await buildx.getSecret(`${key}=${secret}`); |
126 | | - console.log(`secretArgs: ${secretArgs}`); |
127 | | - expect(secretArgs).toEqual(`id=${key},src=${tmpNameSync}`); |
128 | | - const secretContent = await fs.readFileSync(tmpNameSync, 'utf-8'); |
129 | | - console.log(`secretValue: ${secretContent}`); |
130 | | - expect(secretContent).toEqual(secret); |
| 122 | + ['A_SECRET=abcdef0123456789', 'A_SECRET', 'abcdef0123456789', false], |
| 123 | + ['GIT_AUTH_TOKEN=abcdefghijklmno=0123456789', 'GIT_AUTH_TOKEN', 'abcdefghijklmno=0123456789', false], |
| 124 | + ['MY_KEY=c3RyaW5nLXdpdGgtZXF1YWxzCg==', 'MY_KEY', 'c3RyaW5nLXdpdGgtZXF1YWxzCg==', false], |
| 125 | + ['aaaaaaaa', '', '', true], |
| 126 | + ['aaaaaaaa=', '', '', true], |
| 127 | + ['=bbbbbbb', '', '', true] |
| 128 | + ])('given %p key and %p secret', async (kvp, key, secret, invalid) => { |
| 129 | + try { |
| 130 | + const secretArgs = await buildx.getSecret(kvp); |
| 131 | + expect(true).toBe(!invalid); |
| 132 | + console.log(`secretArgs: ${secretArgs}`); |
| 133 | + expect(secretArgs).toEqual(`id=${key},src=${tmpNameSync}`); |
| 134 | + const secretContent = await fs.readFileSync(tmpNameSync, 'utf-8'); |
| 135 | + console.log(`secretValue: ${secretContent}`); |
| 136 | + expect(secretContent).toEqual(secret); |
| 137 | + } catch (err) { |
| 138 | + expect(true).toBe(invalid); |
| 139 | + } |
131 | 140 | }); |
132 | 141 | }); |
0 commit comments