-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
healthcheck
command (#122)
* Implement healthcheck command * Update ci cache key This should fix the following error in CI: ``` error computing cache key: template: cacheKey:1:47: executing "cacheKey" at <checksum "yarn.lock">: error calling checksum: open /home/circleci/cli/yarn.lock: no such file or directory ``` This is because we don't actually have a yarn lock file * Make the linter happy * Extend `Command`, remove `percyWillRun`.
- Loading branch information
Showing
4 changed files
with
86 additions
and
2 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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {Command, flags} from '@oclif/command' | ||
import * as colors from 'colors' | ||
import Constants from '../services/constants' | ||
import healthCheck from '../utils/health-checker' | ||
|
||
export default class HealthCheck extends Command { | ||
static description = 'Determines if the Percy Agent process is currently running' | ||
static hidden = true | ||
|
||
static flags = { | ||
port: flags.integer({ | ||
char: 'p', | ||
default: Constants.PORT, | ||
description: 'port', | ||
}), | ||
} | ||
|
||
static examples = [ | ||
'$ percy healthcheck', | ||
'$ percy healthcheck --port 6884', | ||
] | ||
|
||
async run() { | ||
const {flags} = this.parse(HealthCheck) | ||
const port = flags.port as number | ||
|
||
await healthCheck(port, { | ||
shouldRetry: () => false, | ||
}) | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import * as chai from 'chai' | ||
import {describe} from 'mocha' | ||
import * as nock from 'nock' | ||
import HealthCheck from '../../src/commands/health-check' | ||
import {captureStdErr, captureStdOut} from '../helpers/stdout' | ||
|
||
const expect = chai.expect | ||
|
||
describe('Health check', () => { | ||
describe('when agent is running', () => { | ||
beforeEach(() => { | ||
nock(/localhost/).get('/percy/healthcheck').reply(200) | ||
}) | ||
|
||
afterEach(() => { | ||
nock.cleanAll() | ||
}) | ||
|
||
it('messages that agent is ready', async () => { | ||
const stdout = await captureStdOut(async () => HealthCheck.run([])) | ||
|
||
expect(stdout).to.contain('[percy] percy is ready.') | ||
}) | ||
}) | ||
|
||
describe('when agent is not running', () => { | ||
beforeEach(() => { | ||
nock(/localhost/).get('/percy/healthcheck').reply(500) | ||
}) | ||
|
||
afterEach(() => { | ||
nock.cleanAll() | ||
}) | ||
|
||
it('messages that agent is not ready', async () => { | ||
const errorStdout = await captureStdErr(async () => HealthCheck.run([])) | ||
|
||
expect(errorStdout).to | ||
.contain('[percy] Failed to establish a connection with http://localhost:5338/percy/healthcheck') | ||
}) | ||
|
||
it('properly passes the port', async () => { | ||
const port = '5899' | ||
const errorStdout = await captureStdErr(async () => | ||
HealthCheck.run(['--port', port]), | ||
) | ||
|
||
expect(errorStdout).to | ||
.contain('[percy] Failed to establish a connection with http://localhost:5899/percy/healthcheck') | ||
}) | ||
}) | ||
}) |