Skip to content

Commit

Permalink
feat(core): initial draft implementation of pluggable CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Faust committed Dec 20, 2019
1 parent c11af3a commit 8465625
Show file tree
Hide file tree
Showing 322 changed files with 13,148 additions and 4,739 deletions.
32 changes: 32 additions & 0 deletions __tests__/unit/core-cli/action-factory.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Console } from "@arkecosystem/core-test-framework";

import { ActionFactory, Container } from "@packages/core-cli/src";

let cli;
beforeEach(() => (cli = new Console()));

describe("ActionFactory", () => {
it("should create an instance", () => {
expect(cli.app.resolve(ActionFactory)).toBeInstanceOf(ActionFactory);
});

describe.each([
["abortErroredProcess", Container.Identifiers.AbortErroredProcess],
["abortMissingProcess", Container.Identifiers.AbortMissingProcess],
["abortRunningProcess", Container.Identifiers.AbortRunningProcess],
["abortStoppedProcess", Container.Identifiers.AbortStoppedProcess],
["abortUnknownProcess", Container.Identifiers.AbortUnknownProcess],
["daemonizeProcess", Container.Identifiers.DaemonizeProcess],
["restartProcess", Container.Identifiers.RestartProcess],
["restartRunningProcess", Container.Identifiers.RestartRunningProcess],
["restartRunningProcessWithPrompt", Container.Identifiers.RestartRunningProcessWithPrompt],
])("%s", (method, binding) => {
it("should call be called", async () => {
const spy = jest.spyOn(cli.app.get(binding), "execute").mockImplementation();

await cli.app.resolve(ActionFactory)[method]();

expect(spy).toHaveBeenCalled();
});
});
});
42 changes: 42 additions & 0 deletions __tests__/unit/core-cli/actions/abort-errored-process.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Container } from "@arkecosystem/core-cli";
import { Console } from "@arkecosystem/core-test-framework";

import { AbortErroredProcess } from "@packages/core-cli/src/actions";

const processName: string = "ark-core";

let cli;
let processManager;
let action;

beforeEach(() => {
cli = new Console();
processManager = cli.app.get(Container.Identifiers.ProcessManager);

// Bind from src instead of dist to collect coverage.
cli.app
.rebind(Container.Identifiers.AbortErroredProcess)
.to(AbortErroredProcess)
.inSingletonScope();
action = cli.app.get(Container.Identifiers.AbortErroredProcess);
});

describe("AbortErroredProcess", () => {
it("should not throw if the process does exist", () => {
const spy = jest.spyOn(processManager, "isErrored").mockReturnValue(false);

expect(action.execute(processName)).toBeUndefined();
expect(spy).toHaveBeenCalled();

spy.mockClear();
});

it("should throw if the process does not exist", () => {
const spy = jest.spyOn(processManager, "isErrored").mockReturnValue(true);

expect(() => action.execute(processName)).toThrow(`The "${processName}" process has errored.`);
expect(spy).toHaveBeenCalled();

spy.mockClear();
});
});
42 changes: 42 additions & 0 deletions __tests__/unit/core-cli/actions/abort-missing-process.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Container } from "@arkecosystem/core-cli";
import { Console } from "@arkecosystem/core-test-framework";

import { AbortMissingProcess } from "@packages/core-cli/src/actions";

const processName: string = "ark-core";

let cli;
let processManager;
let action;

beforeEach(() => {
cli = new Console();
processManager = cli.app.get(Container.Identifiers.ProcessManager);

// Bind from src instead of dist to collect coverage.
cli.app
.rebind(Container.Identifiers.AbortMissingProcess)
.to(AbortMissingProcess)
.inSingletonScope();
action = cli.app.get(Container.Identifiers.AbortMissingProcess);
});

describe("AbortMissingProcess", () => {
it("should not throw if the process does exist", () => {
const spy = jest.spyOn(processManager, "missing").mockReturnValue(false);

expect(action.execute(processName)).toBeUndefined();
expect(spy).toHaveBeenCalled();

spy.mockClear();
});

it("should throw if the process does not exist", () => {
const spy = jest.spyOn(processManager, "missing").mockReturnValue(true);

expect(() => action.execute(processName)).toThrow(`The "${processName}" process does not exist.`);
expect(spy).toHaveBeenCalled();

spy.mockClear();
});
});
42 changes: 42 additions & 0 deletions __tests__/unit/core-cli/actions/abort-running-process.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Container } from "@arkecosystem/core-cli";
import { Console } from "@arkecosystem/core-test-framework";

import { AbortRunningProcess } from "@packages/core-cli/src/actions";

const processName: string = "ark-core";

let cli;
let processManager;
let action;

beforeEach(() => {
cli = new Console();
processManager = cli.app.get(Container.Identifiers.ProcessManager);

// Bind from src instead of dist to collect coverage.
cli.app
.rebind(Container.Identifiers.AbortRunningProcess)
.to(AbortRunningProcess)
.inSingletonScope();
action = cli.app.get(Container.Identifiers.AbortRunningProcess);
});

describe("AbortRunningProcess", () => {
it("should not throw if the process does exist", () => {
const spy = jest.spyOn(processManager, "isOnline").mockReturnValue(false);

expect(action.execute(processName)).toBeUndefined();
expect(spy).toHaveBeenCalled();

spy.mockClear();
});

it("should throw if the process does not exist", () => {
const spy = jest.spyOn(processManager, "isOnline").mockReturnValue(true);

expect(() => action.execute(processName)).toThrow(`The "${processName}" process is already running.`);
expect(spy).toHaveBeenCalled();

spy.mockClear();
});
});
42 changes: 42 additions & 0 deletions __tests__/unit/core-cli/actions/abort-stopped-process.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Container } from "@arkecosystem/core-cli";
import { Console } from "@arkecosystem/core-test-framework";

import { AbortStoppedProcess } from "@packages/core-cli/src/actions";

const processName: string = "ark-core";

let cli;
let processManager;
let action;

beforeEach(() => {
cli = new Console();
processManager = cli.app.get(Container.Identifiers.ProcessManager);

// Bind from src instead of dist to collect coverage.
cli.app
.rebind(Container.Identifiers.AbortStoppedProcess)
.to(AbortStoppedProcess)
.inSingletonScope();
action = cli.app.get(Container.Identifiers.AbortStoppedProcess);
});

describe("AbortStoppedProcess", () => {
it("should not throw if the process does exist", () => {
const spy = jest.spyOn(processManager, "isStopped").mockReturnValue(false);

expect(action.execute(processName)).toBeUndefined();
expect(spy).toHaveBeenCalled();

spy.mockClear();
});

it("should throw if the process does not exist", () => {
const spy = jest.spyOn(processManager, "isStopped").mockReturnValue(true);

expect(() => action.execute(processName)).toThrow(`The "${processName}" process is not running.`);
expect(spy).toHaveBeenCalled();

spy.mockClear();
});
});
42 changes: 42 additions & 0 deletions __tests__/unit/core-cli/actions/abort-unknown-process.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Container } from "@arkecosystem/core-cli";
import { Console } from "@arkecosystem/core-test-framework";

import { AbortUnknownProcess } from "@packages/core-cli/src/actions";

const processName: string = "ark-core";

let cli;
let processManager;
let action;

beforeEach(() => {
cli = new Console();
processManager = cli.app.get(Container.Identifiers.ProcessManager);

// Bind from src instead of dist to collect coverage.
cli.app
.rebind(Container.Identifiers.AbortUnknownProcess)
.to(AbortUnknownProcess)
.inSingletonScope();
action = cli.app.get(Container.Identifiers.AbortUnknownProcess);
});

describe("AbortUnknownProcess", () => {
it("should not throw if the process does exist", () => {
const spy = jest.spyOn(processManager, "isUnknown").mockReturnValue(false);

expect(action.execute(processName)).toBeUndefined();
expect(spy).toHaveBeenCalled();

spy.mockClear();
});

it("should throw if the process does not exist", () => {
const spy = jest.spyOn(processManager, "isUnknown").mockReturnValue(true);

expect(() => action.execute(processName)).toThrow(`The "${processName}" process has entered an unknown state.`);
expect(spy).toHaveBeenCalled();

spy.mockClear();
});
});
Loading

0 comments on commit 8465625

Please sign in to comment.