|
| 1 | +import {describe, expect, it, jest, test} from '@jest/globals'; |
1 | 2 | import * as fs from 'fs';
|
2 | 3 | import * as path from 'path';
|
3 | 4 | import * as semver from 'semver';
|
4 | 5 | import * as exec from '@actions/exec';
|
5 |
| - |
6 | 6 | import * as buildx from '../src/buildx';
|
7 | 7 | import * as context from '../src/context';
|
8 | 8 |
|
@@ -53,94 +53,36 @@ describe('getDigest', () => {
|
53 | 53 | });
|
54 | 54 |
|
55 | 55 | describe('isLocalOrTarExporter', () => {
|
56 |
| - // prettier-ignore |
57 | 56 | test.each([
|
58 |
| - [ |
59 |
| - [ |
60 |
| - 'type=registry,ref=user/app', |
61 |
| - ], |
62 |
| - false |
63 |
| - ], |
64 |
| - [ |
65 |
| - [ |
66 |
| - 'type=docker', |
67 |
| - ], |
68 |
| - false |
69 |
| - ], |
70 |
| - [ |
71 |
| - [ |
72 |
| - 'type=local,dest=./release-out' |
73 |
| - ], |
74 |
| - true |
75 |
| - ], |
76 |
| - [ |
77 |
| - [ |
78 |
| - 'type=tar,dest=/tmp/image.tar' |
79 |
| - ], |
80 |
| - true |
81 |
| - ], |
82 |
| - [ |
83 |
| - [ |
84 |
| - 'type=docker', |
85 |
| - 'type=tar,dest=/tmp/image.tar' |
86 |
| - ], |
87 |
| - true |
88 |
| - ], |
89 |
| - [ |
90 |
| - [ |
91 |
| - '"type=tar","dest=/tmp/image.tar"' |
92 |
| - ], |
93 |
| - true |
94 |
| - ], |
95 |
| - [ |
96 |
| - [ |
97 |
| - '" type= local" , dest=./release-out' |
98 |
| - ], |
99 |
| - true |
100 |
| - ], |
101 |
| - [ |
102 |
| - [ |
103 |
| - '.' |
104 |
| - ], |
105 |
| - true |
106 |
| - ], |
107 |
| - ])( |
108 |
| - 'given %p returns %p', |
109 |
| - async (outputs: Array<string>, expected: boolean) => { |
110 |
| - expect(buildx.isLocalOrTarExporter(outputs)).toEqual(expected); |
111 |
| - } |
112 |
| - ); |
| 57 | + [['type=registry,ref=user/app'], false], |
| 58 | + [['type=docker'], false], |
| 59 | + [['type=local,dest=./release-out'], true], |
| 60 | + [['type=tar,dest=/tmp/image.tar'], true], |
| 61 | + [['type=docker', 'type=tar,dest=/tmp/image.tar'], true], |
| 62 | + [['"type=tar","dest=/tmp/image.tar"'], true], |
| 63 | + [['" type= local" , dest=./release-out'], true], |
| 64 | + [['.'], true] |
| 65 | + ])('given %p returns %p', async (outputs: Array<string>, expected: boolean) => { |
| 66 | + expect(buildx.isLocalOrTarExporter(outputs)).toEqual(expected); |
| 67 | + }); |
113 | 68 | });
|
114 | 69 |
|
115 | 70 | describe('isAvailable', () => {
|
116 |
| - const execSpy: jest.SpyInstance = jest.spyOn(exec, 'getExecOutput'); |
| 71 | + const execSpy = jest.spyOn(exec, 'getExecOutput'); |
117 | 72 | buildx.isAvailable();
|
118 | 73 |
|
| 74 | + // eslint-disable-next-line jest/no-standalone-expect |
119 | 75 | expect(execSpy).toHaveBeenCalledWith(`docker`, ['buildx'], {
|
120 | 76 | silent: true,
|
121 | 77 | ignoreReturnCode: true
|
122 | 78 | });
|
123 | 79 | });
|
124 | 80 |
|
125 | 81 | describe('getVersion', () => {
|
126 |
| - async function isDaemonRunning() { |
127 |
| - return await exec |
128 |
| - .getExecOutput(`docker`, ['version', '--format', '{{.Server.Os}}'], { |
129 |
| - ignoreReturnCode: true, |
130 |
| - silent: true |
131 |
| - }) |
132 |
| - .then(res => { |
133 |
| - return !res.stdout.includes(' ') && res.exitCode == 0; |
134 |
| - }); |
135 |
| - } |
136 |
| - (isDaemonRunning() ? it : it.skip)( |
137 |
| - 'valid', |
138 |
| - async () => { |
139 |
| - const version = await buildx.getVersion(); |
140 |
| - expect(semver.valid(version)).not.toBeNull(); |
141 |
| - }, |
142 |
| - 100000 |
143 |
| - ); |
| 82 | + it('valid', async () => { |
| 83 | + const version = await buildx.getVersion(); |
| 84 | + expect(semver.valid(version)).not.toBeNull(); |
| 85 | + }); |
144 | 86 | });
|
145 | 87 |
|
146 | 88 | describe('parseVersion', () => {
|
@@ -187,6 +129,7 @@ describe('getSecret', () => {
|
187 | 129 | const secretValue = await fs.readFileSync(tmpNameSync, 'utf-8');
|
188 | 130 | expect(secretValue).toEqual(exValue);
|
189 | 131 | } catch (err) {
|
| 132 | + // eslint-disable-next-line jest/no-conditional-expect |
190 | 133 | expect(true).toBe(invalid);
|
191 | 134 | }
|
192 | 135 | });
|
|
0 commit comments