@@ -2,14 +2,15 @@ import {expect, jest, test} from '@jest/globals';
2
2
import * as path from 'path' ;
3
3
4
4
import { loginStandard , logout } from '../src/docker' ;
5
- import { Exec } from '@docker/actions-toolkit/lib/exec' ;
5
+
6
+ import { Docker } from '@docker/actions-toolkit/lib/docker/docker' ;
6
7
7
8
process . env [ 'RUNNER_TEMP' ] = path . join ( __dirname , 'runner' ) ;
8
9
9
10
test ( 'loginStandard calls exec' , async ( ) => {
10
11
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
11
12
// @ts -ignore
12
- const execSpy = jest . spyOn ( Exec , 'getExecOutput' ) . mockImplementation ( async ( ) => {
13
+ const execSpy = jest . spyOn ( Docker , 'getExecOutput' ) . mockImplementation ( async ( ) => {
13
14
return {
14
15
exitCode : expect . any ( Number ) ,
15
16
stdout : expect . any ( Function ) ,
@@ -23,7 +24,13 @@ test('loginStandard calls exec', async () => {
23
24
24
25
await loginStandard ( registry , username , password ) ;
25
26
26
- expect ( execSpy ) . toHaveBeenCalledWith ( `docker` , [ 'login' , '--password-stdin' , '--username' , username , registry ] , {
27
+ expect ( execSpy ) . toHaveBeenCalledTimes ( 1 ) ;
28
+ const callfunc = execSpy . mock . calls [ 0 ] ;
29
+ if ( callfunc && callfunc [ 1 ] ) {
30
+ // we don't want to check env opt
31
+ callfunc [ 1 ] . env = undefined ;
32
+ }
33
+ expect ( execSpy ) . toHaveBeenCalledWith ( [ 'login' , '--password-stdin' , '--username' , username , registry ] , {
27
34
input : Buffer . from ( password ) ,
28
35
silent : true ,
29
36
ignoreReturnCode : true
@@ -33,7 +40,7 @@ test('loginStandard calls exec', async () => {
33
40
test ( 'logout calls exec' , async ( ) => {
34
41
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
35
42
// @ts -ignore
36
- const execSpy = jest . spyOn ( Exec , 'getExecOutput' ) . mockImplementation ( async ( ) => {
43
+ const execSpy = jest . spyOn ( Docker , 'getExecOutput' ) . mockImplementation ( async ( ) => {
37
44
return {
38
45
exitCode : expect . any ( Number ) ,
39
46
stdout : expect . any ( Function ) ,
@@ -45,7 +52,13 @@ test('logout calls exec', async () => {
45
52
46
53
await logout ( registry ) ;
47
54
48
- expect ( execSpy ) . toHaveBeenCalledWith ( `docker` , [ 'logout' , registry ] , {
55
+ expect ( execSpy ) . toHaveBeenCalledTimes ( 1 ) ;
56
+ const callfunc = execSpy . mock . calls [ 0 ] ;
57
+ if ( callfunc && callfunc [ 1 ] ) {
58
+ // we don't want to check env opt
59
+ callfunc [ 1 ] . env = undefined ;
60
+ }
61
+ expect ( execSpy ) . toHaveBeenCalledWith ( [ 'logout' , registry ] , {
49
62
ignoreReturnCode : true
50
63
} ) ;
51
64
} ) ;
0 commit comments