-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
267 additions
and
10 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 |
---|---|---|
|
@@ -29,5 +29,8 @@ module.exports = { | |
}, | ||
init: () => { | ||
return pool.query(initScript); | ||
}, | ||
end: () => { | ||
return pool.end(); | ||
} | ||
}; |
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,92 @@ | ||
'use strict'; | ||
|
||
const test = require('tape'); | ||
const supertest = require('supertest'); | ||
const proxyquire = require('proxyquire'); | ||
|
||
test('test liveness ok', t => { | ||
const mockDb = { | ||
init: () => { | ||
return Promise.resolve(); | ||
}, | ||
query: (query, cb) => { | ||
cb(null, true); | ||
} | ||
}; | ||
|
||
const app = proxyquire('../app', { | ||
'./lib/db': mockDb | ||
}); | ||
|
||
supertest(app) | ||
.get('/api/health/liveness') | ||
.expect(200) | ||
.then(response => { | ||
t.equal(response.text, 'OK', 'should return OK'); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
test('test liveness not ok', t => { | ||
const mockDb = { | ||
init: () => { | ||
return Promise.resolve(); | ||
}, | ||
query: (query, cb) => { | ||
cb('error'); | ||
} | ||
}; | ||
|
||
const app = proxyquire('../app', { | ||
'./lib/db': mockDb | ||
}); | ||
|
||
supertest(app) | ||
.get('/api/health/liveness') | ||
.expect(500) | ||
.then(response => { | ||
t.equal(response.text, 'not ok', 'should return not ok'); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
test('SIGTERM', t => { | ||
const mockDb = { | ||
init: () => { | ||
return Promise.resolve(); | ||
}, | ||
end: () => { | ||
t.end(); | ||
} | ||
}; | ||
|
||
process.on = (signal, cb) => { | ||
if (signal === 'SIGTERM') { | ||
cb(); | ||
} | ||
}; | ||
|
||
proxyquire('../app', { | ||
'./lib/db': mockDb | ||
}); | ||
}); | ||
|
||
test('test swagger ui', t => { | ||
const mockDb = { | ||
init: () => { | ||
return Promise.resolve(); | ||
} | ||
}; | ||
|
||
const app = proxyquire('../app', { | ||
'./lib/db': mockDb | ||
}); | ||
|
||
supertest(app) | ||
.get('/api-docs/') | ||
.expect('Content-Type', /text\/html/) | ||
.expect(200) | ||
.then(() => { | ||
t.end(); | ||
}); | ||
}); |