mirror of
https://github.com/docker/login-action.git
synced 2025-02-22 10:20:25 +00:00
pre-checkin
Signed-off-by: Fedor Dikarev <fedor.dikarev@gmail.com>
This commit is contained in:
parent
6cade5565f
commit
4b2f504712
2 changed files with 32 additions and 49 deletions
|
@ -1,4 +1,4 @@
|
|||
import { expect, jest, test, } from '@jest/globals';
|
||||
import {expect, jest, test} from '@jest/globals';
|
||||
|
||||
// import * as dockerModule from '../src/docker';
|
||||
|
||||
|
@ -6,55 +6,42 @@ import { login } from '../src/docker';
|
|||
import {Docker} from '@docker/actions-toolkit/lib/docker/docker';
|
||||
|
||||
test('login retries function', async () => {
|
||||
let stderr_strings: string[] = []
|
||||
let call_count: number = -1
|
||||
let stderr_strings: string[] = [];
|
||||
let call_count: number = -1;
|
||||
|
||||
// const execSpy = jest.spyOn(Docker, 'getExecOutput').mockImplementation(async () => {
|
||||
Docker.getExecOutput = jest.fn(async () => {
|
||||
call_count++
|
||||
console.log(`Mock: ${call_count}, ${stderr_strings}`)
|
||||
call_count++;
|
||||
console.log(`Mock: ${call_count}, ${stderr_strings}`);
|
||||
if (call_count >= stderr_strings.length) {
|
||||
return {
|
||||
exitCode: 0,
|
||||
stdout: 'Mock success',
|
||||
stderr: ''
|
||||
}
|
||||
};
|
||||
}
|
||||
return {
|
||||
exitCode: 1,
|
||||
stdout: '',
|
||||
stderr: stderr_strings[(call_count) % stderr_strings.length]
|
||||
}
|
||||
})
|
||||
stderr: stderr_strings[call_count % stderr_strings.length]
|
||||
};
|
||||
});
|
||||
|
||||
const username = 'dbowie';
|
||||
const password = 'groundcontrol';
|
||||
const registry = 'https://ghcr.io';
|
||||
|
||||
stderr_strings = [
|
||||
'mock error, failed with status: 408 Request Timeout',
|
||||
'mock error, failed with status: 502 Request Timeout',
|
||||
'mock error, failed with status: 400 Request Timeout',
|
||||
]
|
||||
call_count = -1
|
||||
stderr_strings = ['mock error, failed with status: 408 Request Timeout', 'mock error, failed with status: 502 Request Timeout', 'mock error, failed with status: 400 Request Timeout'];
|
||||
call_count = -1;
|
||||
await expect(async () => {
|
||||
await login(registry, username, password, 'false', ['408', '400'], 5, 0.1);
|
||||
})
|
||||
.rejects
|
||||
.toThrow("mock error, failed with status: 502 Request Timeout");
|
||||
}).rejects.toThrow('mock error, failed with status: 502 Request Timeout');
|
||||
expect(Docker.getExecOutput).toHaveBeenCalledTimes(2);
|
||||
|
||||
stderr_strings = [
|
||||
'not matching error',
|
||||
'mock error, failed with status: 502 Request Timeout',
|
||||
'mock error, failed with status: 400 Request Timeout',
|
||||
]
|
||||
call_count = -1
|
||||
stderr_strings = ['not matching error', 'mock error, failed with status: 502 Request Timeout', 'mock error, failed with status: 400 Request Timeout'];
|
||||
call_count = -1;
|
||||
await expect(async () => {
|
||||
await login(registry, username, password, 'false', ['408', '400'], 5, 0.1);
|
||||
})
|
||||
.rejects
|
||||
.toThrow('not matching error');
|
||||
}).rejects.toThrow('not matching error');
|
||||
expect(Docker.getExecOutput).toHaveBeenCalledTimes(2 + 1);
|
||||
|
||||
});
|
||||
|
|
|
@ -1,44 +1,40 @@
|
|||
import { expect, jest, test, } from '@jest/globals';
|
||||
import {expect, jest, test} from '@jest/globals';
|
||||
|
||||
import {login} from '../src/docker';
|
||||
import {Docker} from '@docker/actions-toolkit/lib/docker/docker';
|
||||
|
||||
test('login retries success function', async () => {
|
||||
let stderr_strings: string[] = []
|
||||
let call_count: number = -1
|
||||
let stderr_strings: string[] = [];
|
||||
let call_count: number = -1;
|
||||
|
||||
Docker.getExecOutput = jest.fn(async () => {
|
||||
call_count++
|
||||
console.log(`Mock: ${call_count}, ${stderr_strings}`)
|
||||
call_count++;
|
||||
console.log(`Mock: ${call_count}, ${stderr_strings}`);
|
||||
if (call_count >= stderr_strings.length) {
|
||||
return {
|
||||
exitCode: 0,
|
||||
stdout: 'Mock success',
|
||||
stderr: ''
|
||||
}
|
||||
};
|
||||
}
|
||||
return {
|
||||
exitCode: 1,
|
||||
stdout: '',
|
||||
stderr: stderr_strings[(call_count) % stderr_strings.length]
|
||||
}
|
||||
})
|
||||
stderr: stderr_strings[call_count % stderr_strings.length]
|
||||
};
|
||||
});
|
||||
|
||||
const username = 'dbowie';
|
||||
const password = 'groundcontrol';
|
||||
const registry = 'https://ghcr.io';
|
||||
|
||||
stderr_strings = []
|
||||
call_count = -1
|
||||
stderr_strings = [];
|
||||
call_count = -1;
|
||||
await login(registry, username, password, 'false', ['408', '502', '400'], 5, 0.1);
|
||||
expect(Docker.getExecOutput).toHaveBeenCalledTimes(1);
|
||||
|
||||
stderr_strings = [
|
||||
'mock error, failed with status: 408 Request Timeout',
|
||||
'mock error, failed with status: 502 Request Timeout',
|
||||
'mock error, failed with status: 400 Request Timeout',
|
||||
]
|
||||
call_count = -1
|
||||
stderr_strings = ['mock error, failed with status: 408 Request Timeout', 'mock error, failed with status: 502 Request Timeout', 'mock error, failed with status: 400 Request Timeout'];
|
||||
call_count = -1;
|
||||
await login(registry, username, password, 'false', ['408', '502', '400'], 5, 0.1);
|
||||
expect(Docker.getExecOutput).toHaveBeenCalledTimes(1 + 4);
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue