@@ -6,6 +6,8 @@ import * as context from '../src/context';
6
6
import * as semver from 'semver' ;
7
7
import * as exec from '@actions/exec' ;
8
8
9
+ const tmpNameSync = path . join ( '/tmp/.docker-setup-buildx-jest' , '.tmpname-jest' ) . split ( path . sep ) . join ( path . posix . sep ) ;
10
+
9
11
jest . spyOn ( context , 'tmpDir' ) . mockImplementation ( ( ) : string => {
10
12
const tmpDir = path . join ( '/tmp/.docker-setup-buildx-jest' ) . split ( path . sep ) . join ( path . posix . sep ) ;
11
13
if ( ! fs . existsSync ( tmpDir ) ) {
@@ -14,6 +16,10 @@ jest.spyOn(context, 'tmpDir').mockImplementation((): string => {
14
16
return tmpDir ;
15
17
} ) ;
16
18
19
+ jest . spyOn ( context , 'tmpNameSync' ) . mockImplementation ( ( ) : string => {
20
+ return tmpNameSync ;
21
+ } ) ;
22
+
17
23
describe ( 'isAvailable' , ( ) => {
18
24
const execSpy : jest . SpyInstance = jest . spyOn ( exec , 'getExecOutput' ) ;
19
25
buildx . isAvailable ( ) ;
@@ -119,3 +125,37 @@ describe('install', () => {
119
125
expect ( fs . existsSync ( buildxBin ) ) . toBe ( true ) ;
120
126
} , 100000 ) ;
121
127
} ) ;
128
+
129
+ describe ( 'getConfig' , ( ) => {
130
+ test . each ( [
131
+ [ 'debug = true' , false , 'debug = true' , false ] ,
132
+ [ `notfound.toml` , true , '' , true ] ,
133
+ [
134
+ `${ path . join ( __dirname , 'fixtures' , 'buildkitd.toml' ) . split ( path . sep ) . join ( path . posix . sep ) } ` ,
135
+ true ,
136
+ `debug = true
137
+ [registry."docker.io"]
138
+ mirrors = ["mirror.gcr.io"]
139
+ ` ,
140
+ false
141
+ ]
142
+ ] ) ( 'given %p config' , async ( val , file , exValue , invalid ) => {
143
+ try {
144
+ let config : string ;
145
+ if ( file ) {
146
+ config = await buildx . getConfigFile ( val ) ;
147
+ } else {
148
+ config = await buildx . getConfigInline ( val ) ;
149
+ }
150
+ expect ( true ) . toBe ( ! invalid ) ;
151
+ console . log ( `config: ${ config } ` ) ;
152
+ expect ( config ) . toEqual ( `${ tmpNameSync } ` ) ;
153
+ const configValue = await fs . readFileSync ( tmpNameSync , 'utf-8' ) ;
154
+ console . log ( `configValue: ${ configValue } ` ) ;
155
+ expect ( configValue ) . toEqual ( exValue ) ;
156
+ } catch ( err ) {
157
+ console . log ( err ) ;
158
+ expect ( true ) . toBe ( invalid ) ;
159
+ }
160
+ } ) ;
161
+ } ) ;
0 commit comments