Skip to content

Commit

Permalink
test(matchLabels): add test for bug reported in [1]
Browse files Browse the repository at this point in the history
[1]:#90
  • Loading branch information
Silas Boyd-Wickizer committed Mar 9, 2017
1 parent 9e1f2d6 commit 8a48e6e
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 74 deletions.
74 changes: 0 additions & 74 deletions test/api-group.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,79 +144,5 @@ describe('lib.api-group', () => {
});
});

describe('.match', () => {
beforeTesting('int', done => {
common.changeName(err => {
assume(err).is.falsy();
async.each([
{ body: pod('pod0') },
{ body: pod('pod1') }
], common.api.ns.po.post.bind(common.api.ns.po), done);
});
});
beforeTesting('unit', () => {
nock(common.api.url)
.get(`/api/v1/namespaces/${ common.currentName }/pods`)
.query({ labelSelector: 'name in (pod0),service notin (service0)' })
.reply(200, {
kind: 'PodList',
items: [{
kind: 'Pod'
}]
});
});

it('GETs with labelSelector', done => {
common.api.ns.po.match([{
key: 'name',
operator: 'In',
values: ['pod0']
}, {
key: 'service',
operator: 'NotIn',
values: ['service0']
}]).get((err, pods) => {
assume(err).is.falsy();
assume(pods.kind).is.equal('PodList');
assume(pods.items).has.length(1);
done();
});
});
});
describe('.matchLabels', () => {
beforeTesting('int', done => {
common.changeName(err => {
assume(err).is.falsy();
async.each([
{ body: pod('pod0') },
{ body: pod('pod1') }
], common.api.ns.po.post.bind(common.api.ns.po), done);
});
});
beforeTesting('unit', () => {
nock(common.api.url)
.get(`/api/v1/namespaces/${ common.currentName }/pods`)
.query({ labelSelector: 'name in (pod0),service in (service1)' })
.reply(200, {
kind: 'PodList',
items: [{
kind: 'Pod'
}]
});
});

it('GETs with labelSelector', done => {
common.api.ns.po.matchLabels({
name: 'pod0',
service: 'service1'
}).get((err, pods) => {
assume(err).is.falsy();
assume(pods.kind).is.equal('PodList');
assume(pods.items).has.length(1);
done();
});
});
});

common.afterTesting('int', common.cleanupName);
});
163 changes: 163 additions & 0 deletions test/base.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
'use strict';

const assume = require('assume');
const async = require('async');
const nock = require('nock');

const common = require('./common');
const beforeTesting = common.beforeTesting;

function pod(name) {
return {
kind: 'Pod',
metadata: {
name: name,
labels: {
name: name,
service: 'service1'
}
},
spec: {
containers: [{
name: name,
image: 'doesnotmatter',
imagePullPolicy: 'IfNotPresent'
}]
}
};
}

const testPvc = {
kind: 'PersistentVolumeClaim',
apiVersion: 'v1',
metadata: {
name: 'test-claim',
labels: {
app: 'test'
},
annotations: {
'volume.beta.kubernetes.io/storage-class': 'slow'
},
},
spec: {
accessModes: [ 'ReadWriteOnce' ],
resources: {
requests: {
storage: '1Mi'
}
}
}
};

describe('lib.base', () => {
describe('.BaseObject', () => {

describe('.match', () => {
beforeTesting('int', done => {
common.changeName(err => {
assume(err).is.falsy();
async.each([
{ body: pod('pod0') },
{ body: pod('pod1') }
], common.api.ns.po.post.bind(common.api.ns.po), done);
});
});
beforeTesting('unit', () => {
nock(common.api.url)
.get(`/api/v1/namespaces/${ common.currentName }/pods`)
.query({ labelSelector: 'name in (pod0),service notin (service0)' })
.reply(200, {
kind: 'PodList',
items: [{
kind: 'Pod'
}]
});
});

it('GETs with labelSelector', done => {
common.api.ns.po.match([{
key: 'name',
operator: 'In',
values: ['pod0']
}, {
key: 'service',
operator: 'NotIn',
values: ['service0']
}]).get((err, pods) => {
assume(err).is.falsy();
assume(pods.kind).is.equal('PodList');
assume(pods.items).has.length(1);
done();
});
});
});

describe('.po.matchLabels', () => {
beforeTesting('int', done => {
common.changeName(err => {
assume(err).is.falsy();
async.each([
{ body: pod('pod0') },
{ body: pod('pod1') }
], common.api.ns.po.post.bind(common.api.ns.po), done);
});
});
beforeTesting('unit', () => {
nock(common.api.url)
.get(`/api/v1/namespaces/${ common.currentName }/pods`)
.query({ labelSelector: 'name in (pod0),service in (service1)' })
.reply(200, {
kind: 'PodList',
items: [{
kind: 'Pod'
}]
});
});

it('GETs with labelSelector', done => {
common.api.ns.po.matchLabels({
name: 'pod0',
service: 'service1'
}).get((err, pods) => {
assume(err).is.falsy();
assume(pods.kind).is.equal('PodList');
assume(pods.items).has.length(1);
done();
});
});
});
});

describe('.pvc.matchLabels', () => {
beforeTesting('int', done => {
common.changeName(err => {
assume(err).is.falsy();
common.api.ns.pvc.post({ body: testPvc }, done);
});
});
beforeTesting('unit', () => {
nock(common.api.url)
.get(`/api/v1/namespaces/${ common.currentName }/persistentvolumeclaims`)
.query({ labelSelector: 'app in (test)' })
.reply(200, {
kind: 'PersistentVolumeClaimList',
items: [{
kind: 'PersistentVolumeClaim'
}]
});
});

it('GETs with labelSelector', done => {
common.api.ns.pvc.matchLabels({
app: 'test'
}).get((err, pvcs) => {
assume(err).is.falsy();
assume(pvcs.kind).is.equal('PersistentVolumeClaimList');
assume(pvcs.items).has.length(1);
done();
});
});
});

common.afterTesting('int', common.cleanupName);
});

0 comments on commit 8a48e6e

Please sign in to comment.