|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const { expect } = require('chai') |
| 4 | +const deploymentTransform = require('./deployment') |
| 5 | +const pod = require('./pod') |
| 6 | + |
| 7 | +describe('Transform Deployment', () => { |
| 8 | + let deploymentChart |
| 9 | + |
| 10 | + beforeEach(() => { |
| 11 | + deploymentChart = { |
| 12 | + metadata: { |
| 13 | + selfLink: 'self/deployment/foo', |
| 14 | + creationTimestamp: 1234 |
| 15 | + }, |
| 16 | + spec: { |
| 17 | + replicas: 2, |
| 18 | + template: { |
| 19 | + spec: { |
| 20 | + name: 'My Pod', |
| 21 | + containers: [ |
| 22 | + { |
| 23 | + image: 'risingstack/foo:v1' |
| 24 | + } |
| 25 | + ] |
| 26 | + } |
| 27 | + } |
| 28 | + } |
| 29 | + } |
| 30 | + }) |
| 31 | + |
| 32 | + describe('spec.template transform', () => { |
| 33 | + it('should call pod transform with default values', function () { |
| 34 | + this.sandbox.spy(pod, 'transform') |
| 35 | + |
| 36 | + deploymentTransform({}, deploymentChart) |
| 37 | + expect(pod.transform).to.be.calledWith({}, deploymentChart.spec.template, undefined) |
| 38 | + }) |
| 39 | + |
| 40 | + it('should call pod transform with initial values', function () { |
| 41 | + this.sandbox.spy(pod, 'transform') |
| 42 | + |
| 43 | + deploymentTransform({ foo: 'bar' }, deploymentChart) |
| 44 | + expect(pod.transform).to.be.calledWith({ foo: 'bar' }, deploymentChart.spec.template, undefined) |
| 45 | + }) |
| 46 | + |
| 47 | + it('should call pod transform with scope', function () { |
| 48 | + this.sandbox.spy(pod, 'transform') |
| 49 | + |
| 50 | + deploymentTransform({}, deploymentChart, 'myScope') |
| 51 | + expect(pod.transform).to.be.calledWith({}, deploymentChart.spec.template, 'myScope') |
| 52 | + }) |
| 53 | + |
| 54 | + it('should merge pod transform values and chart', function () { |
| 55 | + this.sandbox.stub(pod, 'transform').returns({ |
| 56 | + values: { pod: 'pod-value' }, |
| 57 | + chart: { spec: { containers: [] } } |
| 58 | + }) |
| 59 | + |
| 60 | + const { values, chart } = deploymentTransform({ initial: 'initial-value' }, deploymentChart) |
| 61 | + expect(chart.spec.template.spec).to.be.eql({ |
| 62 | + name: 'My Pod', |
| 63 | + containers: [ |
| 64 | + { |
| 65 | + image: 'risingstack/foo:v1' |
| 66 | + } |
| 67 | + ] |
| 68 | + }) |
| 69 | + expect(values).to.have.property('initial', 'initial-value') |
| 70 | + expect(values).to.have.property('pod', 'pod-value') |
| 71 | + }) |
| 72 | + }) |
| 73 | + |
| 74 | + describe('spec.replicas transform', () => { |
| 75 | + it('should transform replicas', () => { |
| 76 | + const { values, chart } = deploymentTransform({}, deploymentChart) |
| 77 | + |
| 78 | + expect(values.replicas).to.be.equal(2) |
| 79 | + expect(chart.spec.replicas).to.be.equal('{{ .Values.replicas | default 2 }}') |
| 80 | + }) |
| 81 | + |
| 82 | + it('should respect scope', () => { |
| 83 | + const { values, chart } = deploymentTransform({}, deploymentChart, 'myDeployment') |
| 84 | + |
| 85 | + expect(values.replicas).to.be.equal(2) |
| 86 | + expect(chart.spec.replicas).to.be.equal('{{ .Values.myDeployment.replicas | default 2 }}') |
| 87 | + }) |
| 88 | + }) |
| 89 | + |
| 90 | + describe('meta and status', () => { |
| 91 | + it('should cleanup meta and status', () => { |
| 92 | + const { chart } = deploymentTransform({}, deploymentChart) |
| 93 | + |
| 94 | + expect(chart.metadata.selfLink).to.be.equal(undefined) |
| 95 | + expect(chart.metadata.creationTimestamp).to.be.equal(undefined) |
| 96 | + }) |
| 97 | + }) |
| 98 | +}) |
0 commit comments