-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from oslabs-beta/health
added health check
- Loading branch information
Showing
13 changed files
with
336 additions
and
135 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
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,61 @@ | ||
const checkHandler = require("../../../lib/custom-services/healthcheck-handlers/check"); | ||
|
||
const _statusMap = { | ||
service1: "serving", | ||
service2: "notserving" | ||
}; | ||
|
||
const mockSend = jest.fn(); | ||
const mockThrow = jest.fn(); | ||
const mockGetStatus = jest.fn(x => { | ||
if (!x) { | ||
return mockServer._statusMap; | ||
} | ||
return mockServer._statusMap[x]; | ||
}); | ||
|
||
const mockServer = { | ||
_statusMap, | ||
getStatus: mockGetStatus, | ||
check: checkHandler | ||
}; | ||
|
||
function callBuilder(payload) { | ||
return { | ||
body: payload, | ||
send: mockSend, | ||
throw: mockThrow | ||
}; | ||
} | ||
|
||
describe("Tests for health check handler", () => { | ||
beforeEach(() => { | ||
mockSend.mockClear(); | ||
mockThrow.mockClear(); | ||
}); | ||
|
||
it("Passes back whole status map if no services passed", () => { | ||
mockServer.check(callBuilder({ services: [] })); | ||
expect(mockSend.mock.calls[0][0].hasOwnProperty("health")).toBeTruthy(); | ||
expect( | ||
mockSend.mock.calls[0][0]["health"][0].service === "service1" || | ||
mockSend.mock.calls[0][0]["health"][0].service === "service2" | ||
).toBeTruthy(); | ||
}); | ||
|
||
it("uses getStatus method on Server", () => { | ||
mockServer.check(callBuilder({ services: ["service1"] })); | ||
expect(mockGetStatus.mock.calls.length).toBeGreaterThanOrEqual(1); | ||
}); | ||
|
||
it("handles if specific service name passed", () => { | ||
mockServer.check(callBuilder({ services: ["service1"] })); | ||
expect(mockSend.mock.calls[0][0].hasOwnProperty("health")).toBeTruthy(); | ||
expect(mockSend.mock.calls[0][0]["health"].length).toEqual(1); | ||
}); | ||
|
||
it("emits an error if wrong service name passed", () => { | ||
mockServer.check(callBuilder({ services: ["service3"] })); | ||
expect(mockThrow.mock.calls[0][0]).toBeInstanceOf(Error); | ||
}); | ||
}); |
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
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,12 +1,14 @@ | ||
const grpc = require('grpc'); | ||
const protoLoader = require('@grpc/proto-loader'); | ||
const grpc = require("grpc"); | ||
const protoLoader = require("@grpc/proto-loader"); | ||
|
||
const build = require('./lib/build'); | ||
const Server = require('./lib/Server'); | ||
const Stub = require('./lib/Stub'); | ||
const build = require("./lib/build"); | ||
const Server = require("./lib/Server"); | ||
const Stub = require("./lib/Stub"); | ||
const HealthStub = require("./lib/HealthStub"); | ||
|
||
module.exports = { | ||
Server, | ||
Stub, | ||
build | ||
build, | ||
HealthStub | ||
}; |
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,9 @@ | ||
const Stub = require("./Stub"); | ||
const healthcheck = require("./custom-services/healthcheck-pkg"); | ||
class HealthStub extends Stub { | ||
constructor(port) { | ||
super(healthcheck.HealthCheck, port); | ||
} | ||
} | ||
|
||
module.exports = HealthStub; |
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
Oops, something went wrong.