compose-action/src/index.test.ts
dvag-gloeckner-daniel 7098fdc4f5
Some checks failed
Internal - Main - Continuous Integration / ci (push) Has been cancelled
Internal - Main - Continuous Integration / release (push) Has been cancelled
Need fix to Issue / main (push) Has been cancelled
Mark stale issues and pull requests / main (push) Has been cancelled
feat: make service log level configurable
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
2025-06-19 13:03:41 +02:00

73 lines
2.9 KiB
TypeScript

import * as core from "@actions/core";
import { DockerComposeService } from "./services/docker-compose.service";
import { InputService } from "./services/input.service";
import { LoggerService, LogLevel } from "./services/logger.service";
import { DockerComposeInstallerService } from "./services/docker-compose-installer.service";
let setFailedMock: jest.SpiedFunction<typeof core.setFailed>;
let getInputsMock: jest.SpiedFunction<typeof InputService.prototype.getInputs>;
let debugMock: jest.SpiedFunction<typeof LoggerService.prototype.debug>;
let infoMock: jest.SpiedFunction<typeof LoggerService.prototype.info>;
let installMock: jest.SpiedFunction<typeof DockerComposeInstallerService.prototype.install>;
let upMock: jest.SpiedFunction<typeof DockerComposeService.prototype.up>;
describe("index", () => {
beforeEach(() => {
jest.clearAllMocks();
setFailedMock = jest.spyOn(core, "setFailed").mockImplementation();
infoMock = jest.spyOn(LoggerService.prototype, "info").mockImplementation();
debugMock = jest.spyOn(LoggerService.prototype, "debug").mockImplementation();
getInputsMock = jest.spyOn(InputService.prototype, "getInputs");
installMock = jest.spyOn(DockerComposeInstallerService.prototype, "install");
upMock = jest.spyOn(DockerComposeService.prototype, "up");
});
it("calls run when imported", async () => {
getInputsMock.mockImplementation(() => ({
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
services: [],
composeFlags: [],
upFlags: [],
downFlags: [],
cwd: "/current/working/dir",
composeVersion: null,
githubToken: null,
serviceLogLevel: LogLevel.Debug,
}));
installMock.mockResolvedValue("1.2.3");
upMock.mockResolvedValueOnce();
// eslint-disable-next-line @typescript-eslint/no-require-imports
await require("../src/index");
await new Promise((resolve) => setTimeout(resolve, 0));
expect(infoMock).toHaveBeenNthCalledWith(1, "Setting up docker compose");
expect(infoMock).toHaveBeenNthCalledWith(2, "docker compose version: 1.2.3");
// Verify that all of the functions were called correctly
expect(debugMock).toHaveBeenNthCalledWith(
1,
'inputs: {"dockerFlags":[],"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir","composeVersion":null,"githubToken":null,"serviceLogLevel":"debug"}'
);
expect(infoMock).toHaveBeenNthCalledWith(3, "Bringing up docker compose service(s)");
expect(upMock).toHaveBeenCalledWith({
dockerFlags: [],
composeFiles: ["docker-compose.yml"],
services: [],
composeFlags: [],
upFlags: [],
cwd: "/current/working/dir",
serviceLogger: debugMock,
});
expect(setFailedMock).not.toHaveBeenCalled();
expect(infoMock).toHaveBeenNthCalledWith(4, "docker compose service(s) are up");
});
});