-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Emilien Escalle <[email protected]>
- Loading branch information
Showing
13 changed files
with
329 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,56 @@ | ||
/** | ||
* Unit tests for the action's entrypoint, src/index.ts | ||
*/ | ||
import * as core from "@actions/core"; | ||
import { DockerComposeService } from "./services/docker-compose.service"; | ||
import { InputService } from "./services/input.service"; | ||
import { LoggerService } from "./services/logger.service"; | ||
|
||
import * as main from "./main"; | ||
|
||
// Mock the action's entrypoint | ||
const runMock = jest.spyOn(main, "run").mockImplementation(); | ||
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 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"); | ||
upMock = jest.spyOn(DockerComposeService.prototype, "up"); | ||
}); | ||
|
||
it("calls run when imported", async () => { | ||
getInputsMock.mockImplementation(() => ({ | ||
composeFiles: ["docker-compose.yml"], | ||
services: [], | ||
composeFlags: [], | ||
upFlags: [], | ||
downFlags: [], | ||
cwd: "/current/working/dir", | ||
})); | ||
|
||
upMock.mockResolvedValueOnce(); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-require-imports | ||
require("../src/index"); | ||
await require("../src/index"); | ||
|
||
// Verify that all of the functions were called correctly | ||
expect(debugMock).toHaveBeenNthCalledWith( | ||
1, | ||
'inputs: {"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir"}' | ||
); | ||
|
||
expect(upMock).toHaveBeenCalledWith({ | ||
composeFiles: ["docker-compose.yml"], | ||
services: [], | ||
composeFlags: [], | ||
upFlags: [], | ||
downFlags: [], | ||
cwd: "/current/working/dir", | ||
}); | ||
|
||
expect(runMock).toHaveBeenCalled(); | ||
expect(setFailedMock).not.toHaveBeenCalled(); | ||
expect(infoMock).toHaveBeenCalledWith("compose started"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
/** | ||
* The entrypoint for the action. | ||
*/ | ||
import { run, RunAction } from "./main"; | ||
import { RunCallback, run } from "./runner"; | ||
import { DockerComposeService } from "./services/docker-compose.service"; | ||
import { Inputs } from "./services/input.service"; | ||
import { LoggerService } from "./services/logger.service"; | ||
|
||
const callback: RunCallback = async ( | ||
inputs: Inputs, | ||
loggerService: LoggerService, | ||
dockerComposeService: DockerComposeService | ||
) => { | ||
await dockerComposeService.up(inputs); | ||
loggerService.info("compose started"); | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
run(RunAction.UP); | ||
run(callback); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.