From 1a78bc10dc0501309d794815a528b78e4739d82f Mon Sep 17 00:00:00 2001 From: Fedor Dikarev Date: Thu, 23 Jan 2025 09:29:25 +0100 Subject: [PATCH] add tests for retries Signed-off-by: Fedor Dikarev --- __tests__/retries.test.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 __tests__/retries.test.ts diff --git a/__tests__/retries.test.ts b/__tests__/retries.test.ts new file mode 100644 index 0000000..f1f88f5 --- /dev/null +++ b/__tests__/retries.test.ts @@ -0,0 +1,37 @@ +import { expect, jest, test, } from '@jest/globals'; +import * as path from 'path'; + +// import * as dockerModule from '../src/docker'; + +import { login } from '../src/docker'; +import { Docker } from '@docker/actions-toolkit/lib/docker/docker'; + +test('login retries function', async () => { + const 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', + ] + let call_count: number = 0 + + Docker.getExecOutput = jest.fn(async () => { + 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] + } + }) + + const username = 'dbowie'; + const password = 'groundcontrol'; + const registry = 'https://ghcr.io'; + + await login(registry, username, password, 'false', ['408', '502', '400'], 5, 0.5); +});