-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Promise API): Experimental support for a promise-based API (#133)
This preserves the original callback-based "core" implementation and layers the promised-based API on top of that core implementation. The goal is start using and iterating on the promised-based API even if we expect the underlying implementation to evolve (e.g., we could consider replacing the core callback-based implementation with a promise one). See #37 for discussion. Example usage: ```js const core = new api.Core({ url: 'http://my-k8s-api-server.com', promises: true }); async function main() { try { const pods = await core.ns('kube-system').po.get(); console.log(`Watching: ${ JSON.stringify(pods, null, 2) }`); const stream = core.ns('kube-system').po.getStream({ qs: { watch: true }}); stream.on('data', data => { console.log(data.toString()); }); stream.on('error', err => { throw err; }); stream.on('end', () => { console.log('end'); }); } catch (error) { console.log(error); } } main(); ```
- Loading branch information
Showing
10 changed files
with
116 additions
and
18 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
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
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
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,41 @@ | ||
'use strict'; | ||
|
||
const assume = require('assume'); | ||
const nock = require('nock'); | ||
|
||
const common = require('./common'); | ||
const only = common.only; | ||
const beforeTestingEach = common.beforeTestingEach; | ||
|
||
describe('lib.promise', () => { | ||
describe('Core', () => { | ||
beforeTestingEach('unit', () => { | ||
nock(common.api.url) | ||
.get(`/api/v1/namespaces/${ common.currentName }/pods/test-pod`) | ||
.reply(200, { | ||
kind: 'Pod', | ||
metadata: { name: 'test-pod' } | ||
}); | ||
}); | ||
|
||
only('unit', '.get returns a Pod via a promise', done => { | ||
const pods = common.corePromise.ns.po('test-pod').get(); | ||
pods.then(object => { | ||
assume(object.kind).is.equal('Pod'); | ||
assume(object.metadata.name).is.equal('test-pod'); | ||
done(); | ||
}); | ||
}); | ||
only('unit', '.getStream returns the Pod via a stream', done => { | ||
const stream = common.corePromise.ns.po('test-pod').getStream(); | ||
const pieces = []; | ||
stream.on('data', data => pieces.push(data.toString())); | ||
stream.on('error', err => assume(err).is.falsy()); | ||
stream.on('end', () => { | ||
const object = JSON.parse(pieces.join('')); | ||
assume(object.kind).is.equal('Pod'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |