-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add namespaced support to objects other than
namespaces
(#40)
There are several objects/entities that are namespaced by Kubernetes objects. `/api/v1/namespaces/{namespace}/pods/{name}/log` is an obvious one, but there's more. For example: * Proxy objects (e.g., `/api/v1/namespaces/{namespace}/services/{name}/proxy/`) * Deployment related objects (e.g., `/apis/extensions/v1beta1/namespaces/{namespace}/deployments/{name}/rollback`) * ... This PR implements a story for handling these cases and changes the documentation to encourage users to use namespaced functionality by default (e.g., `api.ns.po('foo').get(print)` vs `api.ns.po.get(foo, print)`).
- Loading branch information
Showing
6 changed files
with
227 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
'use strict'; | ||
|
||
const assume = require('assume'); | ||
const nock = require('nock'); | ||
|
||
const common = require('./common'); | ||
const api = common.api; | ||
const only = common.only; | ||
const defaultName = common.defaultName; | ||
const beforeTesting = common.beforeTesting; | ||
const beforeTestingEach = common.beforeTestingEach; | ||
|
||
const testPod = { | ||
kind: 'Pod', | ||
metadata: { | ||
name: 'test-pod' | ||
}, | ||
spec: { | ||
containers: [ | ||
{ | ||
image: 'does-not-matter:latest', | ||
name: 'test' | ||
} | ||
] | ||
} | ||
}; | ||
|
||
describe('lib.pods', () => { | ||
|
||
describe('.post', () => { | ||
beforeTesting('int', api.wipe); | ||
beforeTestingEach('unit', () => { | ||
nock(api.url) | ||
.post(`/api/v1/namespaces/${ defaultName }/pods`) | ||
.reply(200, { | ||
kind: 'Pod', | ||
metadata: { name: 'test-pod' } | ||
}); | ||
}); | ||
|
||
it('succeeds creating a new pod', done => { | ||
api.ns.pods.post({ body: testPod }, (err, pod) => { | ||
assume(err).is.falsy(); | ||
assume(pod.metadata.name).is.equal('test-pod'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('.get', () => { | ||
beforeTesting('int', done => { | ||
api.wipe(err => { | ||
assume(err).is.falsy(); | ||
api.ns.pods.post({ body: testPod }, done); | ||
}); | ||
}); | ||
beforeTestingEach('unit', () => { | ||
nock(api.url) | ||
.get(`/api/v1/namespaces/${ defaultName }/pods/test-pod`) | ||
.reply(200, { | ||
kind: 'Pod', | ||
metadata: { name: 'test-pod' } | ||
}); | ||
}); | ||
it('returns the Pod', done => { | ||
api.ns.pods('test-pod').get((err, pod) => { | ||
assume(err).is.falsy(); | ||
assume(pod.kind).is.equal('Pod'); | ||
done(); | ||
}); | ||
}); | ||
only('unit', 'returns the Pod via the legacy method', done => { | ||
api.ns.pods.get('test-pod', (err, pod) => { | ||
assume(err).is.falsy(); | ||
assume(pod.kind).is.equal('Pod'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('.delete', () => { | ||
beforeTesting('int', done => { | ||
api.wipe(err => { | ||
assume(err).is.falsy(); | ||
api.ns.pods.post({ body: testPod }, done); | ||
}); | ||
}); | ||
beforeTestingEach('unit', () => { | ||
nock(api.url) | ||
.delete(`/api/v1/namespaces/${ defaultName }/pods/test-pod`) | ||
.reply(200, { kind: 'Pod' }); | ||
}); | ||
it('deletes the Pod', done => { | ||
api.ns.pods('test-pod').delete((err, pod) => { | ||
assume(err).is.falsy(); | ||
assume(pod.kind).is.equal('Pod'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('.log', () => { | ||
beforeTestingEach('unit', () => { | ||
nock(api.url) | ||
.get(`/api/v1/namespaces/${ defaultName }/pods/test-pod/log`) | ||
.reply(200, 'some log contents'); | ||
}); | ||
only('unit', 'returns log contents', done => { | ||
api.ns.pods('test-pod').log.get((err, contents) => { | ||
assume(err).is.falsy(); | ||
assume(contents).is.equal('some log contents'); | ||
done(); | ||
}); | ||
}); | ||
only('unit', 'returns log contents via legacy method', done => { | ||
api.ns.pods.log('test-pod', (err, contents) => { | ||
assume(err).is.falsy(); | ||
assume(contents).is.equal('some log contents'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |