@@ -86,7 +86,9 @@ describe("Docker images", (): void => {
86
86
87
87
const assertSaveDockerImages = (
88
88
cacheHit : boolean ,
89
+ key : string ,
89
90
readOnly = false ,
91
+ prevSave = false ,
90
92
) : void => {
91
93
expect ( core . getInput ) . nthCalledWith < [ string , InputOptions ] > ( 1 , "key" , {
92
94
required : true ,
@@ -95,12 +97,20 @@ describe("Docker images", (): void => {
95
97
if ( ! cacheHit ) {
96
98
expect ( core . getInput ) . lastCalledWith ( "read-only" ) ;
97
99
if ( ! readOnly ) {
98
- expect ( core . getState ) . lastCalledWith ( docker . DOCKER_IMAGES_LIST ) ;
99
- expect ( core . info ) . nthCalledWith < [ string ] > ( 1 , "Listing Docker images." ) ;
100
- expect ( util . execBashCommand ) . nthCalledWith < [ string ] > (
101
- 1 ,
102
- 'docker image list --format "{{ .Repository }}:{{ .Tag }}"' ,
103
- ) ;
100
+ expect ( cache . restoreCache ) . lastCalledWith ( [ "" ] , key , [ ] , {
101
+ lookupOnly : true ,
102
+ } ) ;
103
+ if ( ! prevSave ) {
104
+ expect ( core . getState ) . lastCalledWith ( docker . DOCKER_IMAGES_LIST ) ;
105
+ expect ( core . info ) . nthCalledWith < [ string ] > (
106
+ 1 ,
107
+ "Listing Docker images." ,
108
+ ) ;
109
+ expect ( util . execBashCommand ) . nthCalledWith < [ string ] > (
110
+ 1 ,
111
+ 'docker image list --format "{{ .Repository }}:{{ .Tag }}"' ,
112
+ ) ;
113
+ }
104
114
}
105
115
}
106
116
} ;
@@ -109,6 +119,7 @@ describe("Docker images", (): void => {
109
119
key : string ,
110
120
cacheHit : boolean ,
111
121
readOnly : boolean ,
122
+ prevSave : boolean ,
112
123
preexistingImages : string [ ] ,
113
124
newImages : string [ ] ,
114
125
) : Promise < void > => {
@@ -117,14 +128,19 @@ describe("Docker images", (): void => {
117
128
if ( ! cacheHit ) {
118
129
core . getInput . mockReturnValueOnce ( readOnly . toString ( ) ) ;
119
130
if ( ! readOnly ) {
120
- core . getState . mockReturnValueOnce ( preexistingImages . join ( "\n" ) ) ;
121
- const images = preexistingImages . concat ( newImages ) ;
122
- util . execBashCommand . mockResolvedValueOnce ( images . join ( "\n" ) ) ;
131
+ if ( prevSave ) {
132
+ cache . restoreCache . mockResolvedValueOnce ( key ) ;
133
+ } else {
134
+ cache . restoreCache . mockResolvedValueOnce ( undefined ) ;
135
+ core . getState . mockReturnValueOnce ( preexistingImages . join ( "\n" ) ) ;
136
+ const images = preexistingImages . concat ( newImages ) ;
137
+ util . execBashCommand . mockResolvedValueOnce ( images . join ( "\n" ) ) ;
138
+ }
123
139
}
124
140
}
125
141
await docker . saveDockerImages ( ) ;
126
142
127
- assertSaveDockerImages ( cacheHit , readOnly ) ;
143
+ assertSaveDockerImages ( cacheHit , key , readOnly , prevSave ) ;
128
144
} ;
129
145
130
146
const assertCacheNotSaved = ( ) : void => {
@@ -147,6 +163,15 @@ describe("Docker images", (): void => {
147
163
assertCacheNotSaved ( ) ;
148
164
} ;
149
165
166
+ const assertSavePrevSave = ( key : string ) : void => {
167
+ expect ( core . info ) . lastCalledWith (
168
+ "A cache miss occurred during the initial attempt to load Docker " +
169
+ `images, but subsequently a cache with a matching key, ${ key } , was saved. ` +
170
+ "This can occur when run in parallel. Not saving cache." ,
171
+ ) ;
172
+ assertCacheNotSaved ( ) ;
173
+ } ;
174
+
150
175
const assertNoNewImagesToSave = ( ) : void => {
151
176
expect ( util . execBashCommand ) . toHaveBeenCalledTimes ( 1 ) ;
152
177
expect ( core . info ) . lastCalledWith ( "No Docker images to save" ) ;
@@ -230,24 +255,28 @@ describe("Docker images", (): void => {
230
255
) ;
231
256
232
257
testProp (
233
- "are saved unless cache hit, in read-only mode, or new Docker image list is empty" ,
258
+ "are saved unless cache hit, in read-only mode, cache already saved, or " +
259
+ "new Docker image list is empty" ,
234
260
[
235
261
fullUnicodeString ( ) ,
236
262
boolean ( ) ,
237
263
boolean ( ) ,
264
+ boolean ( ) ,
238
265
uniquePair ( dockerImages ( ) , dockerImages ( ) ) ,
239
266
] ,
240
267
async (
241
268
key : string ,
242
269
cacheHit : boolean ,
243
270
readOnly : boolean ,
271
+ prevSave : boolean ,
244
272
[ preexistingImages , newImages ] : [ string [ ] , string [ ] ] ,
245
273
) : Promise < void > => {
246
274
jest . clearAllMocks ( ) ;
247
275
await mockedSaveDockerImages (
248
276
key ,
249
277
cacheHit ,
250
278
readOnly ,
279
+ prevSave ,
251
280
preexistingImages ,
252
281
newImages ,
253
282
) ;
@@ -256,6 +285,8 @@ describe("Docker images", (): void => {
256
285
assertSaveCacheHit ( key ) ;
257
286
} else if ( readOnly ) {
258
287
assertSaveReadOnly ( key ) ;
288
+ } else if ( prevSave ) {
289
+ assertSavePrevSave ( key ) ;
259
290
} else if ( newImages . length === 0 ) {
260
291
assertNoNewImagesToSave ( ) ;
261
292
} else {
@@ -264,10 +295,11 @@ describe("Docker images", (): void => {
264
295
} ,
265
296
{
266
297
examples : [
267
- [ "my-key" , false , false , [ [ "preexisting-image" ] , [ "new-image" ] ] ] ,
268
- [ "my-key" , false , false , [ [ "preexisting-image" ] , [ ] ] ] ,
269
- [ "my-key" , false , true , [ [ "preexisting-image" ] , [ "new-image" ] ] ] ,
270
- [ "my-key" , true , false , [ [ "preexisting-image" ] , [ "new-image" ] ] ] ,
298
+ [ "my-key" , false , false , false , [ [ "preexisting-image" ] , [ "new-image" ] ] ] ,
299
+ [ "my-key" , false , false , false , [ [ "preexisting-image" ] , [ ] ] ] ,
300
+ [ "my-key" , false , true , false , [ [ "preexisting-image" ] , [ "new-image" ] ] ] ,
301
+ [ "my-key" , true , false , false , [ [ "preexisting-image" ] , [ "new-image" ] ] ] ,
302
+ [ "my-key" , false , false , true , [ [ "preexisting-image" ] , [ "new-image" ] ] ] ,
271
303
] ,
272
304
} ,
273
305
) ;
0 commit comments