diff --git a/lib/tester/index.ts b/lib/tester/index.ts index 0180fc7..7a7e45f 100644 --- a/lib/tester/index.ts +++ b/lib/tester/index.ts @@ -197,7 +197,7 @@ export default class Tester implements ITester { source: this.me, destination: agent, timings: result.timings, - result: 'pass' + result: result.statusCode === 200 ? 'pass' : 'fail' } this.metrics.handleTCPTestResult(mappedResult) return mappedResult diff --git a/test/tester.test.ts b/test/tester.test.ts index 0ca944a..3b58752 100644 --- a/test/tester.test.ts +++ b/test/tester.test.ts @@ -58,7 +58,7 @@ describe('Tester', () => { should(result[0].result).eql('pass') }) - it('should should capture a failed ping as an error', async () => { + it('should should capture a failed ping as an fail', async () => { const udpClient = td.object() const udpPingResult = td.object() udpPingResult.success = true @@ -92,4 +92,32 @@ describe('Tester', () => { const result = await sut.runTCPTests([agent]) should(result[0].result).eql('pass') }) + + it('should capture a 5xx code as a fail', async () => { + td.when( + got('http://127.0.0.1:8080/readiness', { timeout: 500 }) + ).thenResolve({ statusCode: 500 }) + + const agent = td.object() + agent.ip = '127.0.0.1' + agent.name = 'local' + agent.nodeName = 'some-node' + agent.zone = 'some-zone' + const result = await sut.runTCPTests([agent]) + should(result[0].result).eql('fail') + }) + + it('should capture a failed tcp test as a fail', async () => { + td.when( + got('http://127.0.0.1:8080/readiness', { timeout: 500 }) + ).thenReject(new Error('boom')) + + const agent = td.object() + agent.ip = '127.0.0.1' + agent.name = 'local' + agent.nodeName = 'some-node' + agent.zone = 'some-zone' + const result = await sut.runTCPTests([agent]) + should(result[0].result).eql('fail') + }) })