Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
added new unit test for when the kubernetes api does not respond on t…
Browse files Browse the repository at this point in the history
…he replicaset or deployment endpoints
  • Loading branch information
Fredrik Folkesson authored and Fredrik Folkesson committed Aug 21, 2018
1 parent fa07bbd commit dfc02ad
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions test/unit/orchestration/KubernetesClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ before(() => {
Config.init();
});

beforeEach(() => {
nock('http://localhost:8001').get('/apis/apps/v1/replicasets').reply(200, replicaSetSpecData.endpointsResponse);
nock('http://localhost:8001').get('/apis/apps/v1/deployments').reply(200, deploymentSpecData.endpointsResponse);
});

describe('KubernetesClient', () => {
describe('#listEngines', async () => {
it('should translate the kubernetes endpoints list to a mira engine list', async () => {
Expand All @@ -32,6 +27,8 @@ describe('KubernetesClient', () => {
});

it('should set the kubernetes property to hold the container info', async () => {
nock('http://localhost:8001').get('/apis/apps/v1/replicasets').reply(200, replicaSetSpecData.endpointsResponse);
nock('http://localhost:8001').get('/apis/apps/v1/deployments').reply(200, deploymentSpecData.endpointsResponse);
nock('http://localhost:8001').get('/api/v1/pods?labelSelector=qix-engine').reply(200, podSpecData.endpointsResponse);
const engines = await KubernetesClient.listEngines();
expect(engines[0].kubernetes.pod).to.deep.equal(podSpecData.endpointsResponse.items[0]);
Expand All @@ -42,6 +39,19 @@ describe('KubernetesClient', () => {
expect(engines[1].kubernetes.deployment).to.deep.equal(deploymentSpecData.endpointsResponse.items[0]);
});

it('should not set the replicaset or deployment kubernetes subproperty if the kubernetes API does not return any data on those endpoints', async () => {
nock('http://localhost:8001').get('/apis/apps/v1/replicasets').reply(401);
nock('http://localhost:8001').get('/apis/apps/v1/deployments').reply(401);
nock('http://localhost:8001').get('/api/v1/pods?labelSelector=qix-engine').reply(200, podSpecData.endpointsResponse);
const engines = await KubernetesClient.listEngines();
expect(engines[0].kubernetes.pod).to.deep.equal(podSpecData.endpointsResponse.items[0]);
expect(engines[0].kubernetes.replicaSet).to.be.undefined;
expect(engines[0].kubernetes.deployment).to.be.undefined;
expect(engines[1].kubernetes.pod).to.deep.equal(podSpecData.endpointsResponse.items[1]);
expect(engines[1].kubernetes.replicaSet).to.be.undefined;
expect(engines[1].kubernetes.deployment).to.be.undefined;
});

it('should not set the local and swarm properties', async () => {
nock('http://localhost:8001').get('/api/v1/pods?labelSelector=qix-engine').reply(200, podSpecData.endpointsResponse);
const engines = await KubernetesClient.listEngines();
Expand Down

0 comments on commit dfc02ad

Please sign in to comment.