fix(lease): bad documentation on ttl, throw if not provided (fixes #68)

This commit is contained in:
Connor Peet 2018-05-05 18:55:08 -07:00
Родитель 28258c8847
Коммит 1e9f8113a2
2 изменённых файлов: 4 добавлений и 3 удалений

Просмотреть файл

@ -70,7 +70,7 @@ const enum State {
* const hostPrefix = 'available-hosts/';
*
* function grantLease() {
* const lease = client.lease();
* const lease = client.lease(10); // set a TTL of 10 seconds
*
* lease.on('lost', err => {
* console.log('We lost our lease as a result of this error:', err);
@ -102,7 +102,7 @@ export class Lease extends EventEmitter {
) {
super();
if (ttl < 1) {
if (!ttl || ttl < 1) {
throw new Error(`The TTL in an etcd lease must be at least 1 second. Got: ${ttl}`);
}

Просмотреть файл

@ -28,8 +28,9 @@ describe('lease()', () => {
}
});
it('throws if trying to use too short of a ttl', () => {
it('throws if trying to use too short of a ttl, or an undefined ttl', () => {
expect(() => client.lease(0)).to.throw(/must be at least 1 second/);
expect(() => (<any> client.lease)()).to.throw(/must be at least 1 second/);
});
it('reports a loss and errors if the client is invalid', async () => {