Skip to content

Commit

Permalink
Merge pull request #61 from longgerr/master
Browse files Browse the repository at this point in the history
Fix issue #60: Chart dependencies with conditions are cleared when running test suite
  • Loading branch information
quintush authored Sep 7, 2020
2 parents c8a4898 + 6903947 commit eb6a855
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 9 deletions.
Binary file not shown.
Binary file not shown.
10 changes: 8 additions & 2 deletions __fixtures__/v2/with-subchart/requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@ dependencies:
- name: postgresql
repository: https://kubernetes-charts.storage.googleapis.com
version: 0.8.3
digest: sha256:6ab78c0f011b833b1328a5d917c1761b12b17e662c405456f1dad869c1048a9c
generated: 2018-03-26T15:50:14.210943461+08:00
- name: mysql
repository: https://kubernetes-charts.storage.googleapis.com
version: 1.2.0
- name: redis
repository: https://kubernetes-charts.storage.googleapis.com
version: 10.5.7
digest: sha256:d40b8e91634146ea8a5d54d2319e3fe1fe3241cd232e20a449400f2b66adcac4
generated: "2020-09-02T08:50:32.745002421+08:00"
8 changes: 8 additions & 0 deletions __fixtures__/v2/with-subchart/requirements.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ dependencies:
repository: https://kubernetes-charts.storage.googleapis.com
version: 0.8.3
alias: another-postgresql
- name: mysql
repository: https://kubernetes-charts.storage.googleapis.com
version: 1.2.0
condition: mysql.enabled
- name: redis
repository: https://kubernetes-charts.storage.googleapis.com
version: 10.5.7
condition: redis.enabled
Original file line number Diff line number Diff line change
@@ -1,3 +1,51 @@
should disable sub-charts:
1: |
replicas: 1
template:
metadata:
labels:
app: with-subchart
release: RELEASE-NAME
spec:
containers:
- image: apache:latest
imagePullPolicy: Always
livenessProbe:
httpGet:
path: /
port: 80
name: with-subchart
ports:
- containerPort: 80
readinessProbe:
httpGet:
path: /
port: 80
resources: {}
should enable sub-charts:
1: |
replicas: 1
template:
metadata:
labels:
app: with-subchart
release: RELEASE-NAME
spec:
containers:
- image: apache:latest
imagePullPolicy: Always
livenessProbe:
httpGet:
path: /
port: 80
name: with-subchart
ports:
- containerPort: 80
readinessProbe:
httpGet:
path: /
port: 80
resources: {}
should pass all kinds of assertion:
1: |
replicas: 1
Expand Down
18 changes: 18 additions & 0 deletions __fixtures__/v2/with-subchart/tests/deployment_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,21 @@ tests:
count: 1
- matchSnapshot:
path: spec
- it: should disable sub-charts
values:
- ./values/image.yaml
set:
mysql.enabled: false
redis.enabled: false
asserts:
- matchSnapshot:
path: spec
- it: should enable sub-charts
values:
- ./values/image.yaml
set:
mysql.enabled: true
redis.enabled: true
asserts:
- matchSnapshot:
path: spec
6 changes: 3 additions & 3 deletions unittest/.snapshots/TestV2RunnerWithTestsInSubchart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

Charts: 1 passed, 1 total
Test Suites: 9 passed, 9 total
Tests: 21 passed, 21 total
Snapshot: 9 passed, 9 total
Time: XX.XXXms
Tests: 23 passed, 23 total
Snapshot: 11 passed, 11 total
Time: XX.XXXs


Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

Charts: 1 passed, 1 total
Test Suites: 5 passed, 5 total
Tests: 11 passed, 11 total
Snapshot: 5 passed, 5 total
Time: XX.XXXms
Tests: 13 passed, 13 total
Snapshot: 7 passed, 7 total
Time: XX.XXXs


2 changes: 1 addition & 1 deletion unittest/test_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

var sectionBeginPattern = regexp.MustCompile("( PASS | FAIL |\n*###|\n*Charts:|\n*Snapshot Summary:)")
var timePattern = regexp.MustCompile("Time:\\s+([\\d\\.]+)ms")
var timePattern = regexp.MustCompile("Time:\\s+([\\d\\.]+)(s|ms)")

func makeOutputSnapshotable(originalOutput string) []interface{} {
output := strings.ReplaceAll(originalOutput, "\\", "/")
Expand Down
5 changes: 5 additions & 0 deletions unittest/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,17 @@ func (s *TestSuite) runV2TestJobs(
jobResults := make([]*TestJobResult, len(s.Tests))

for idx, testJob := range s.Tests {
dependenciesBackup := make([]*v2chart.Chart, len(chart.Dependencies))
copy(dependenciesBackup, chart.Dependencies)

jobResult := testJob.RunV2(chart, cache, &TestJobResult{Index: idx})
jobResults[idx] = jobResult

if !jobResult.Passed {
suitePass = false
}

chart.Dependencies = dependenciesBackup
}
return suitePass, jobResults
}
Expand Down

0 comments on commit eb6a855

Please sign in to comment.