Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #12 from gandhiprachi/master
Browse files Browse the repository at this point in the history
Add support for specifying KubeMajorVersion and KubeMinorVersion capa…
  • Loading branch information
aiyengar2 authored Mar 31, 2021
2 parents 8781348 + 1183b9f commit 8324f1c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
2 changes: 2 additions & 0 deletions __fixtures__/basic/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ metadata:
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
major: {{ .Capabilities.KubeVersion.Major }}
minor: {{ .Capabilities.KubeVersion.Minor }}
spec:
replicas: {{ .Values.replicaCount }}
template:
Expand Down
20 changes: 19 additions & 1 deletion unittest/.snapshots/TestRunJobOk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Index: (int) 0,
Passed: (bool) true,
ExecError: (error) <nil>,
AssertsResult: ([]*unittest.AssertionResult) (len=2) {
AssertsResult: ([]*unittest.AssertionResult) (len=4) {
(*unittest.AssertionResult)({
Index: (int) 0,
FailInfo: ([]string) {
Expand All @@ -21,6 +21,24 @@
AssertType: (string) (len=10) "matchRegex",
Not: (bool) false,
CustomInfo: (string) ""
}),
(*unittest.AssertionResult)({
Index: (int) 2,
FailInfo: ([]string) {
},
Passed: (bool) true,
AssertType: (string) (len=5) "equal",
Not: (bool) false,
CustomInfo: (string) ""
}),
(*unittest.AssertionResult)({
Index: (int) 3,
FailInfo: ([]string) {
},
Passed: (bool) true,
AssertType: (string) (len=5) "equal",
Not: (bool) false,
CustomInfo: (string) ""
})
}
})
10 changes: 9 additions & 1 deletion unittest/test_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type TestJob struct {
}
Capabilities struct {
APIVersions []string
KubeVersionMajor string
KubeVersionMinor string
}
// route indicate which chart in the dependency hierarchy
// like "parant-chart", "parent-charts/charts/child-chart"
Expand Down Expand Up @@ -168,7 +170,13 @@ func (t *TestJob) releaseOption() *chartutil.ReleaseOptions {
// get chartutil.CapabilityOptions ready for render
// Only supports APIVersions for now
func (t *TestJob) capabilityOption() *chartutil.Capabilities {
options := chartutil.Capabilities{APIVersions: chartutil.DefaultVersionSet}
options := chartutil.Capabilities{APIVersions: chartutil.DefaultVersionSet, KubeVersion: chartutil.DefaultKubeVersion}
if t.Capabilities.KubeVersionMajor != "" {
options.KubeVersion.Major = t.Capabilities.KubeVersionMajor
}
if t.Capabilities.KubeVersionMinor != "" {
options.KubeVersion.Minor = t.Capabilities.KubeVersionMinor
}
if len(t.Capabilities.APIVersions) > 0 {
var arr []string
arr = append(t.Capabilities.APIVersions, "v1")
Expand Down
13 changes: 12 additions & 1 deletion unittest/test_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ func TestRunJobOk(t *testing.T) {
c, _ := chartutil.Load("../__fixtures__/basic")
manifest := `
it: should work
capabilities:
kubeversionmajor: 2
kubeversionminor: 5
asserts:
- equal:
path: kind
Expand All @@ -66,6 +69,14 @@ asserts:
path: metadata.name
pattern: -basic$
template: deployment.yaml
- equal:
path: metadata.labels.major
value: 2
template: deployment.yaml
- equal:
path: metadata.labels.minor
value: 5
template: deployment.yaml
`
var tj TestJob
yaml.Unmarshal([]byte(manifest), &tj)
Expand All @@ -77,7 +88,7 @@ asserts:

a.Nil(testResult.ExecError)
a.True(testResult.Passed)
a.Equal(2, len(testResult.AssertsResult))
a.Equal(4, len(testResult.AssertsResult))
}

func TestRunJobWithAssertionFail(t *testing.T) {
Expand Down

0 comments on commit 8324f1c

Please sign in to comment.