Skip to content

Commit ccff429

Browse files
author
Peter Marton
committed
test(transform/deployment): cover with tests
1 parent 68b0f68 commit ccff429

File tree

3 files changed

+106
-3
lines changed

3 files changed

+106
-3
lines changed

src/transform/deployment.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
'use strict'
22

33
const fp = require('lodash/fp')
4-
const podTransform = require('./pod')
4+
const pod = require('./pod')
55

66
function transform (inputValues, inputChart, scope) {
77
const valuesPrefix = scope ? `.${scope}` : ''
88
let values = Object.assign({}, inputValues)
99
let chart = Object.assign({}, inputChart)
1010

1111
// Pod
12-
const deploymentPod = podTransform(inputValues, inputChart.spec.template, scope)
12+
const deploymentPod = pod.transform(inputValues, inputChart.spec.template, scope)
1313

1414
values = fp.merge(values)(deploymentPod.values)
1515
chart = fp.merge(chart)({
@@ -27,7 +27,6 @@ function transform (inputValues, inputChart, scope) {
2727
chart.status = undefined
2828
chart.metadata.selfLink = undefined
2929
chart.metadata.creationTimestamp = undefined
30-
chart.spec.template.metadata.creationTimestamp = undefined
3130

3231
return {
3332
values,
@@ -36,3 +35,4 @@ function transform (inputValues, inputChart, scope) {
3635
}
3736

3837
module.exports = transform
38+
module.exports.transform = transform

src/transform/deployment.spec.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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+
})

src/transform/pod.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ function transformContainers (inputValues, inputChart, scope = '') {
8484
return container
8585
})
8686

87+
if (chart.metadata) {
88+
chart.metadata.creationTimestamp = undefined
89+
}
90+
8791
return {
8892
values,
8993
chart
@@ -102,3 +106,4 @@ function transform (inputValues, inputChart, scope = '') {
102106
}
103107

104108
module.exports = transform
109+
module.exports.transform = transform

0 commit comments

Comments
 (0)