done (+42 squashed commit) (#1053)

Squashed commit:

[8058e6aba] 1 error left

[b0157b252] 2 errors

[7fa494907] 4 errors

[03139391e]  6 failures, 4 errors

[7f017ea23] 12 errors

[3e9ad758d] 0 failures, 13 errors

[e24a3cb3e] 3 failures, 13 errors

[6edcaa655] 4 failures 14 errors

[9623bda57] 6 failures, 13 errors

[04c35c995] 4 failed 22 errors

[5f5335c15] 9 failures

[9a33540e2] down to 20 failures

[0e7b73b49] remove old tests

[5cc6d11b7] fixup the resources

[8c508d45a] some more progress

[4acef3c3b] some more work

[85cdb5d06] some ports cleanup

[1987ac2ec] lint before unit

[6fa221789] enable unit tests

[c212b695d] other name

[b78594518] common test name fix

[ef6597e79] indent

[8cbcfb5e4] common test rename

[1ca838c16] seperate common tests

[ef052b022] create two seperate job for common testing

[67eb0e9b3] use devcontainer for release shizzle

[0c47c482b] make it a sudo

[4d8900b16] force install jq

[9660cdd47] try something else

[e2b611917] bump common to run tests (to fix them)

[277241bbf] only use the new devcontainer for the release tests for now...

[9c7b68e0f] Revert "remove setup chart testing action"

This reverts commit 6987914587a58ab5a52a05b836d60ef91f1619d5.

[444914311] Revert "use integrated k3d"

This reverts commit d9bcb2f35d154b0afe1eb851729c37789b6ba0ea. (+6 squashed commit)

Squashed commit:

[313446184] Revert "correct k3s version"

This reverts commit 81fa8a43c41c2449b7411e0d59a3c2bbe0aef1ea.

[41b4d4795] Revert "version name tryout"

This reverts commit bbb8dcead9f9426872390b8f89b1fd0e661534bb.

[b64df97a0] Revert "change version"

This reverts commit 8080395dc80e606769ad9790b35d35fac4d1d3ed.

[ed63220d4] Revert "use k3s kubectl"

This reverts commit ea81735d939e838ad595835ea09b54bff817dd83.

[6267a2908] Revert "use normal kubectl"

This reverts commit 216d3799111d47f65dd20dd85ccb8fbc586a9c2b.

[f48ddde73] Revert "try to set kubectl context"

This reverts commit a5e8a532c5620e0d9d4cb7a53a371ba200265612.

[a5e8a532c] try to set kubectl context

[216d37991] use normal kubectl

[ea81735d9] use k3s kubectl

[8080395dc] change version

[bbb8dcead] version name tryout

[81fa8a43c] correct k3s version

[d9bcb2f35] use integrated k3d

[698791458] remove setup chart testing action

[5bd7cf01d] bump common-test
This commit is contained in:
Kjeld Schouten-Lebbing
2021-09-29 00:11:52 +02:00
committed by GitHub
parent d16997b5e3
commit 88b1719d32
31 changed files with 1034 additions and 2487 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
concurrency: gitpush
container:
image: image: ghcr.io/truecharts/devcontainer:v2.0.0
image: ghcr.io/truecharts/devcontainer:v2.0.0
steps:
- uses: actions/checkout@v2
+13 -19
View File
@@ -48,9 +48,7 @@ jobs:
needs: [changes]
if: ${{ needs.changes.outputs.empty_matrix == 'false' }}
name: App Tests
runs-on: ubuntu-latest
container:
image: ghcr.io/truecharts/devcontainer:v2.0.0
runs-on: ubuntu-20.04
strategy:
matrix: ${{ fromJson(needs.changes.outputs.matrix) }}
fail-fast: false
@@ -95,37 +93,33 @@ jobs:
echo "::set-output name=unittests::false"
fi
- name: Install Helm
if: ${{ matrix.app != '.gitkee' }}
uses: azure/setup-helm@v1
with:
version: v3.5.3
- name: update helm repo cache
run: |
helm repo add truecharts https://truecharts.org
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
- uses: actions/setup-python@v2
if: ${{ matrix.app != '.gitkee' }}
with:
python-version: 3.7
- name: Set up chart-testing
if: ${{ matrix.app != '.gitkee' }}
uses: helm/chart-testing-action@v2.1.0
##
# Unit-Test section
##
- name: Install dependencies
if: ${{ matrix.app == 'common' && matrix.app != '.gitkee' }}
run: |
bundle install
- name: Run common unit tests
if: ${{ matrix.app == 'common' && matrix.app != '.gitkee' }}
run: |
bundle exec m -r tests
##
# Chart-Testing Section
##
- name: Run chart-testing (lint)
if: ${{ matrix.app != '.gitkee' }}
if: ${{ matrix.app != 'common' && matrix.app != '.gitkee' }}
id: lint
run: ct lint --config .github/ct-lint.yaml --charts 'charts/${{ steps.prep-lint.outputs.train }}/${{ matrix.app }}'
+103
View File
@@ -0,0 +1,103 @@
name: "common: Tests"
on:
pull_request:
branches:
- '**'
tags-ignore:
- '**'
paths:
- 'charts/library/**'
- '.github/workflows/common.test.yaml'
- '.github/ct-install.yaml'
- '.github/ct-lint.yaml'
jobs:
unit-and-lint:
name: Unit and Lint tests
runs-on: ubuntu-latest
container:
image: ghcr.io/truecharts/devcontainer:v2.0.0
steps:
- name: Cache helm repo cache
id: cache
uses: actions/cache@v2
with:
key: helmrepocache-${{ github.sha }}
path: |
~/.cache/helm/repository
~/.config/helm/repositories.yaml
- uses: actions/checkout@v2
name: Checkout
with:
fetch-depth: 100
- name: update helm repo cache
run: |
helm repo add truecharts https://truecharts.org
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
- name: Run chart-testing (lint)
run: ct lint --config .github/ct-lint.yaml --charts 'charts/library/common-test'
- name: Run common unit tests
run: |
bundle exec m -r tests
run-tests:
name: Run tests
runs-on: ubuntu-latest
needs: [unit-and-lint]
steps:
- name: Cache helm repo cache
id: cache
uses: actions/cache@v2
with:
key: helmrepocache-${{ github.sha }}
path: |
~/.cache/helm/repository
~/.config/helm/repositories.yaml
- uses: actions/checkout@v2
name: Checkout
with:
fetch-depth: 100
- name: Install Helm
if: ${{ matrix.app != '.gitkee' }}
uses: azure/setup-helm@v1
with:
version: v3.5.3
- name: update helm repo cache
run: |
helm repo add truecharts https://truecharts.org
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
- uses: actions/setup-python@v2
if: ${{ matrix.app != '.gitkee' }}
with:
python-version: 3.7
- name: Set up chart-testing
if: ${{ matrix.app != '.gitkee' }}
uses: helm/chart-testing-action@v2.1.0
##
# Chart-Testing Section
##
- uses: actions/setup-python@v2
if: ${{ matrix.app != '.gitkee' }}
with:
python-version: 3.7
- name: Create k3d cluster
uses: nolar/setup-k3d-k3s@v1
with:
version: v1.19
- name: Run chart-testing (install)
run: ct install --config .github/ct-install.yaml --charts 'charts/library/common-test'
+1 -1
View File
@@ -22,4 +22,4 @@ name: common-test
sources:
- https://github.com/truecharts/apps/tree/master/charts/library/common-test
type: application
version: 3.1.5
version: 3.2.0
@@ -9,6 +9,10 @@ service:
main:
port: 8080
args:
- --port
- '8080'
ingress:
main:
enabled: true
-4
View File
@@ -3,10 +3,6 @@ image:
pullPolicy: IfNotPresent
tag: v1.6.1@sha256:2c52bb2c848038a33e40415c300b655d7976bafaf033ecf4a6679cb9e1715917
args:
- --port
- '8080'
service:
main:
ports:
+1 -1
View File
@@ -15,4 +15,4 @@ maintainers:
name: common
sources: null
type: library
version: 8.0.8
version: 8.0.9
@@ -39,10 +39,10 @@ metadata:
{{- end }}
spec:
accessModes:
- {{ required (printf "accessMode is required for PVC %v" $pvcName) $values.accessMode | quote }}
- {{ ( $values.accessMode | default "ReadWriteOnce" ) | quote }}
resources:
requests:
storage: {{ required (printf "size is required for PVC %v" $pvcName) $values.size | quote }}
storage: {{ $values.size | default "100Gi" | quote }}
{{- if $values.storageClass }}
storageClassName: {{ if (eq "-" $values.storageClass) }}""{{- else if (eq "SCALE-ZFS" $values.storageClass ) }}{{ ( printf "%v-%v" "ix-storage-class" .Release.Name ) }}{{- else }}{{ $values.storageClass | quote }}{{- end }}
{{- end }}
@@ -27,7 +27,6 @@ metadata:
{{ toYaml $values.labels | nindent 4 }}
{{- end }}
annotations:
rollme: {{ randAlphaNum 5 | quote }}
{{- if eq ( $primaryPort.protocol | default "" ) "HTTPS" }}
traefik.ingress.kubernetes.io/service.serversscheme: https
{{- end }}
@@ -1,136 +0,0 @@
package common
import (
"testing"
"github.com/Jeffail/gabs/v2"
"github.com/truecharts/apps/tests/helmunit"
"github.com/stretchr/testify/suite"
)
type AddonCodeserverTestSuite struct {
suite.Suite
Chart helmunit.HelmChart
baseValues string
}
func (suite *AddonCodeserverTestSuite) SetupSuite() {
suite.Chart = helmunit.New("common-test", "../../common-test")
suite.Chart.UpdateDependencies()
suite.baseValues = `
addons:
codeserver:
enabled: true
volumeMounts:
- name: "config"
mountPath: "/data/config"
`
}
// We need this function to kick off the test suite, otherwise
// "go test" won't know about our tests
func TestAddonCodeserver(t *testing.T) {
suite.Run(t, new(AddonCodeserverTestSuite))
}
func (suite *AddonCodeserverTestSuite) TestContainer() {
tests := map[string]struct {
values *string
expectedCodeserverContainer bool
}{
"Default": {values: nil, expectedCodeserverContainer: false},
"AddonEnabled": {values: &suite.baseValues, expectedCodeserverContainer: true},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, nil, tc.values)
if err != nil {
suite.FailNow(err.Error())
}
deploymentManifest := suite.Chart.Manifests.Get("Deployment", "common-test")
suite.Assertions.NotEmpty(deploymentManifest)
containers := deploymentManifest.Path("spec.template.spec.containers").Children()
var codeserverContainer *gabs.Container
for _, container := range containers {
containerName := container.Path("name").Data().(string)
if containerName == "codeserver" {
codeserverContainer = container
break
}
}
if tc.expectedCodeserverContainer {
suite.Assertions.NotEmpty(codeserverContainer)
} else {
suite.Assertions.Empty(codeserverContainer)
}
})
}
}
func (suite *AddonCodeserverTestSuite) TestDeployKey() {
tests := map[string]struct {
values []string
expectSecret bool
expectedSecretName string
}{
"Inline": {values: []string{"addons.codeserver.git.deployKey=test"}, expectSecret: true, expectedSecretName: "common-test-deploykey"},
"InlineBase64": {values: []string{"addons.codeserver.git.deployKeyBase64=dGVzdEtleQ=="}, expectSecret: true, expectedSecretName: "common-test-deploykey"},
"ExistingSecret": {values: []string{"addons.codeserver.git.deployKeySecret=test-secret"}, expectSecret: false, expectedSecretName: "test-secret"},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, &suite.baseValues)
if err != nil {
suite.FailNow(err.Error())
}
secretManifest := suite.Chart.Manifests.Get("Secret", tc.expectedSecretName)
if tc.expectSecret {
suite.Assertions.NotEmpty(secretManifest)
} else {
suite.Assertions.Empty(secretManifest)
}
deploymentManifest := suite.Chart.Manifests.Get("Deployment", "common-test")
suite.Assertions.NotEmpty(deploymentManifest)
containers := deploymentManifest.Path("spec.template.spec.containers").Children()
var codeserverContainer *gabs.Container
for _, container := range containers {
containerName := container.Path("name").Data().(string)
if containerName == "codeserver" {
codeserverContainer = container
break
}
}
suite.Assertions.NotEmpty(codeserverContainer)
volumeMounts := codeserverContainer.Path("volumeMounts").Children()
var gitDeploykeyVolumeMount *gabs.Container
for _, volumeMount := range volumeMounts {
volumeMountName := volumeMount.Path("name").Data().(string)
if volumeMountName == "deploykey" {
gitDeploykeyVolumeMount = volumeMount
break
}
}
suite.Assertions.NotEmpty(gitDeploykeyVolumeMount)
suite.Assertions.EqualValues("/root/.ssh/id_rsa", gitDeploykeyVolumeMount.Path("mountPath").Data())
suite.Assertions.EqualValues("id_rsa", gitDeploykeyVolumeMount.Path("subPath").Data())
volumes := deploymentManifest.Path("spec.template.spec.volumes").Children()
var gitDeploykeyVolume *gabs.Container
for _, volume := range volumes {
volumeName := volume.Path("name").Data().(string)
if volumeName == "deploykey" {
gitDeploykeyVolume = volume
break
}
}
suite.Assertions.NotEmpty(gitDeploykeyVolume)
})
}
}
@@ -1,64 +0,0 @@
package common
import (
"testing"
"github.com/Jeffail/gabs/v2"
"github.com/truecharts/apps/tests/helmunit"
"github.com/stretchr/testify/suite"
)
type AddonNetshootTestSuite struct {
suite.Suite
Chart helmunit.HelmChart
baseValues []string
}
func (suite *AddonNetshootTestSuite) SetupSuite() {
suite.Chart = helmunit.New("common-test", "../../common-test")
suite.Chart.UpdateDependencies()
suite.baseValues = []string{"addons.netshoot.enabled=true"}
}
// We need this function to kick off the test suite, otherwise
// "go test" won't know about our tests
func TestAddonNetshoot(t *testing.T) {
suite.Run(t, new(AddonNetshootTestSuite))
}
func (suite *AddonNetshootTestSuite) TestContainer() {
tests := map[string]struct {
values []string
expectedNetshootContainer bool
}{
"Default": {values: nil, expectedNetshootContainer: false},
"AddonEnabled": {values: suite.baseValues, expectedNetshootContainer: true},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, nil)
if err != nil {
suite.FailNow(err.Error())
}
deploymentManifest := suite.Chart.Manifests.Get("Deployment", "common-test")
suite.Assertions.NotEmpty(deploymentManifest)
containers := deploymentManifest.Path("spec.template.spec.containers").Children()
var netshootContainer *gabs.Container
for _, container := range containers {
containerName := container.Path("name").Data().(string)
if containerName == "netshoot" {
netshootContainer = container
break
}
}
if tc.expectedNetshootContainer {
suite.Assertions.NotEmpty(netshootContainer)
} else {
suite.Assertions.Empty(netshootContainer)
}
})
}
}
@@ -1,64 +0,0 @@
package common
import (
"testing"
"github.com/Jeffail/gabs/v2"
"github.com/truecharts/apps/tests/helmunit"
"github.com/stretchr/testify/suite"
)
type AddonVpnTestSuite struct {
suite.Suite
Chart helmunit.HelmChart
baseValues []string
}
func (suite *AddonVpnTestSuite) SetupSuite() {
suite.Chart = helmunit.New("common-test", "../../common-test")
suite.Chart.UpdateDependencies()
suite.baseValues = []string{"addons.vpn.type=openvpn"}
}
// We need this function to kick off the test suite, otherwise
// "go test" won't know about our tests
func TestAddonVpn(t *testing.T) {
suite.Run(t, new(AddonVpnTestSuite))
}
func (suite *AddonVpnTestSuite) TestContainer() {
tests := map[string]struct {
values []string
expectedVpnContainer bool
}{
"Default": {values: nil, expectedVpnContainer: false},
"AddonEnabled": {values: suite.baseValues, expectedVpnContainer: true},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, nil)
if err != nil {
suite.FailNow(err.Error())
}
deploymentManifest := suite.Chart.Manifests.Get("Deployment", "common-test")
suite.Assertions.NotEmpty(deploymentManifest)
containers := deploymentManifest.Path("spec.template.spec.containers").Children()
var vpnContainer *gabs.Container
for _, container := range containers {
containerName := container.Path("name").Data().(string)
if containerName == "openvpn" {
vpnContainer = container
break
}
}
if tc.expectedVpnContainer {
suite.Assertions.NotEmpty(vpnContainer)
} else {
suite.Assertions.Empty(vpnContainer)
}
})
}
}
@@ -1,303 +0,0 @@
package common
import (
"testing"
"github.com/truecharts/apps/tests/helmunit"
"github.com/stretchr/testify/suite"
)
type ContainerTestSuite struct {
suite.Suite
Chart helmunit.HelmChart
}
func (suite *ContainerTestSuite) SetupSuite() {
suite.Chart = helmunit.New("common-test", "../../common-test")
suite.Chart.UpdateDependencies()
}
// We need this function to kick off the test suite, otherwise
// "go test" won't know about our tests
func TestContainer(t *testing.T) {
suite.Run(t, new(ContainerTestSuite))
}
func (suite *ContainerTestSuite) TestCommand() {
tests := map[string]struct {
values []string
expectedCommand []string
}{
"Default": {values: nil, expectedCommand: nil},
"SingleString": {values: []string{"command=/bin/sh"}, expectedCommand: []string{"/bin/sh"}},
"StringList": {values: []string{"command={/bin/sh,-c}"}, expectedCommand: []string{"/bin/sh", "-c"}},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, nil)
if err != nil {
suite.FailNow(err.Error())
}
deploymentManifest := suite.Chart.Manifests.Get("Deployment", "common-test")
suite.Assertions.NotEmpty(deploymentManifest)
containers := deploymentManifest.Path("spec.template.spec.containers").Children()
containerCommand := containers[0].Path("command")
if tc.expectedCommand == nil {
suite.Assertions.Empty(containerCommand)
} else {
var actualDataList []string
actualData := containerCommand.Children()
for _, key := range actualData {
actualDataList = append(actualDataList, key.Data().(string))
}
suite.Assertions.EqualValues(tc.expectedCommand, actualDataList)
}
})
}
}
func (suite *ContainerTestSuite) TestArgs() {
tests := map[string]struct {
values []string
expectedArgs []string
}{
"Default": {values: nil, expectedArgs: []string{"--port","8080"}},
"SingleString": {values: []string{"args=sleep infinity"}, expectedArgs: []string{"sleep infinity"}},
"StringList": {values: []string{"args={sleep,infinity}"}, expectedArgs: []string{"sleep", "infinity"}},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, nil)
if err != nil {
suite.FailNow(err.Error())
}
deploymentManifest := suite.Chart.Manifests.Get("Deployment", "common-test")
suite.Assertions.NotEmpty(deploymentManifest)
containers := deploymentManifest.Path("spec.template.spec.containers").Children()
containerArgs := containers[0].Path("args")
if tc.expectedArgs == nil {
suite.Assertions.Empty(containerArgs)
} else {
var actualDataList []string
actualData := containerArgs.Children()
for _, key := range actualData {
actualDataList = append(actualDataList, key.Data().(string))
}
suite.Assertions.EqualValues(tc.expectedArgs, actualDataList)
}
})
}
}
func (suite *ContainerTestSuite) TestEnv() {
tests := map[string]struct {
values []string
expectedEnv map[string]string
}{
"Default": {values: nil, expectedEnv: map[string]string{"S6_READ_ONLY_ROOT":"1"}},
"KeyValueString": {values: []string{"env.string=value_of_env"}, expectedEnv: map[string]string{"S6_READ_ONLY_ROOT":"1", "string": "value_of_env"}},
"KeyValueFloat": {values: []string{"env.float=4.2"}, expectedEnv: map[string]string{"S6_READ_ONLY_ROOT":"1", "float": "4.2"}},
"KeyValueBool": {values: []string{"env.bool=false"}, expectedEnv: map[string]string{"S6_READ_ONLY_ROOT":"1", "bool":"false"}},
"KeyValueInt": {values: []string{"env.int=42"}, expectedEnv: map[string]string{"S6_READ_ONLY_ROOT":"1", "int": "42"}},
"KeyValue+ExplicitValueFrom": {values: []string{"env.STATIC_ENV=value_of_env", "env.STATIC_ENV_FROM.valueFrom.fieldRef.fieldPath=spec.nodeName"}, expectedEnv: map[string]string{"S6_READ_ONLY_ROOT":"1", "STATIC_ENV": "value_of_env", "STATIC_ENV_FROM": "spec.nodeName"}},
"ImplicitValueFrom": {values: []string{"env.NODE_NAME.fieldRef.fieldPath=spec.nodeName"}, expectedEnv: map[string]string{"NODE_NAME": "spec.nodeName", "S6_READ_ONLY_ROOT":"1"}},
"Templated": {values: []string{`env.DYN_ENV=\{\{ .Release.Name \}\}-admin`}, expectedEnv: map[string]string{"DYN_ENV": "common-test-admin", "S6_READ_ONLY_ROOT":"1"}},
"Mixed": {
values: []string{
`env.DYN_ENV=\{\{ .Release.Name \}\}-admin`,
"env.STATIC_ENV=value_of_env",
"env.STATIC_EXPLICIT_ENV_FROM.valueFrom.fieldRef.fieldPath=spec.nodeName",
"env.STATIC_IMPLICIT_ENV_FROM.fieldRef.fieldPath=spec.nodeName",
},
expectedEnv: map[string]string{
"DYN_ENV": "common-test-admin",
"S6_READ_ONLY_ROOT": "1",
"STATIC_ENV": "value_of_env",
"STATIC_EXPLICIT_ENV_FROM": "spec.nodeName",
"STATIC_IMPLICIT_ENV_FROM": "spec.nodeName",
},
},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, nil)
if err != nil {
suite.FailNow(err.Error())
}
deploymentManifest := suite.Chart.Manifests.Get("Deployment", "common-test")
suite.Assertions.NotEmpty(deploymentManifest)
containers := deploymentManifest.Path("spec.template.spec.containers").Children()
containerEnv := containers[0].Path("env")
if tc.expectedEnv == nil {
suite.Assertions.Empty(containerEnv)
} else {
actualDataMap := make(map[string]string)
actualData := containerEnv.Children()
for _, value := range actualData {
envVar := value.ChildrenMap()
envName := envVar["name"].Data().(string)
var envValue string
if _, ok := envVar["valueFrom"]; ok {
envValue = value.Path("valueFrom.fieldRef.fieldPath").Data().(string)
} else {
envValue = value.Path("value").Data().(string)
}
actualDataMap[envName] = envValue
}
suite.Assertions.EqualValues(tc.expectedEnv, actualDataMap)
}
})
}
}
func (suite *ContainerTestSuite) TestEnvFrom() {
tests := map[string]struct {
values []string
expectSecret bool
expectedSecretName string
}{
"Default": {values: nil, expectSecret: false, expectedSecretName: ""},
"FromSecret": {values: []string{"secret.STATIC_SECRET=value_of_secret"}, expectSecret: true, expectedSecretName: "common-test"},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, nil)
if err != nil {
suite.FailNow(err.Error())
}
secretManifest := suite.Chart.Manifests.Get("Secret", tc.expectedSecretName)
if tc.expectSecret {
suite.Assertions.NotEmpty(secretManifest)
} else {
suite.Assertions.Empty(secretManifest)
}
deploymentManifest := suite.Chart.Manifests.Get("Deployment", "common-test")
suite.Assertions.NotEmpty(deploymentManifest)
containers := deploymentManifest.Path("spec.template.spec.containers").Children()
containerEnvFrom := containers[0].Path("envFrom").Children()
if !tc.expectSecret {
suite.Assertions.Empty(containerEnvFrom)
} else {
suite.Assertions.EqualValues(tc.expectedSecretName, containerEnvFrom[0].Path("secretRef.name").Data().(string))
}
})
}
}
func (suite *ContainerTestSuite) TestPorts() {
tests := map[string]struct {
values []string
expectedPortName string
expectedPort int
expectedProtocol string
}{
"Default": {values: nil, expectedPortName: "main", expectedPort: 8080, expectedProtocol: "TCP"},
"CustomName": {values: []string{"service.main.ports.main.enabled=false", "service.main.ports.server.enabled=true", "service.main.ports.server.port=8080"}, expectedPortName: "server", expectedPort: 8080, expectedProtocol: "TCP"},
"ProtocolHTTP": {values: []string{"service.main.ports.main.protocol=HTTP"}, expectedPortName: "main", expectedPort: 8080, expectedProtocol: "TCP"},
"ProtocolHTTPS": {values: []string{"service.main.ports.main.protocol=HTTP"}, expectedPortName: "main", expectedPort: 8080, expectedProtocol: "TCP"},
"ProtocolUDP": {values: []string{"service.main.ports.main.protocol=UDP"}, expectedPortName: "main", expectedPort: 8080, expectedProtocol: "UDP"},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, nil)
if err != nil {
suite.FailNow(err.Error())
}
deploymentManifest := suite.Chart.Manifests.Get("Deployment", "common-test")
suite.Assertions.NotEmpty(deploymentManifest)
containers := deploymentManifest.Path("spec.template.spec.containers").Children()
containerPorts := containers[0].Path("ports").Children()
suite.Assertions.NotEmpty(containerPorts[0])
suite.Assertions.EqualValues(tc.expectedPortName, containerPorts[0].Path("name").Data())
suite.Assertions.EqualValues(tc.expectedProtocol, containerPorts[0].Path("protocol").Data())
if tc.expectedPort == 0 {
suite.Assertions.Empty(containerPorts[8080].Path("containerPort").Data())
} else {
suite.Assertions.EqualValues(tc.expectedPort, containerPorts[0].Path("containerPort").Data())
}
})
}
}
func (suite *ContainerTestSuite) TestPersistenceVolumeMounts() {
values := `
persistence:
config:
enabled: true
cache:
enabled: true
type: emptyDir
claimWithCustomMountPath:
enabled: true
mountPath: /custom
accessMode: ReadWriteMany
size: 1G
claimWithSubPath:
enabled: true
existingClaim: myClaim
subPath: "mySubPath"
hostpath-data:
enabled: true
type: hostPath
mountPath: /data
hostPath: /tmp
hostpath-dev:
enabled: true
type: hostPath
hostPath: /dev
subPath: mySubPath
`
tests := map[string]struct {
values *string
volumeToTest string
expectedMountPath string
expectedSubPath string
}{
"MountWithoutMountPath": {values: &values, volumeToTest: "config", expectedMountPath: "/config"},
"EmptyDir": {values: &values, volumeToTest: "cache", expectedMountPath: "/cache"},
"MountWithCustomMountPath": {values: &values, volumeToTest: "claimWithCustomMountPath", expectedMountPath: "/custom"},
"MountWithSubPath": {values: &values, volumeToTest: "claimWithSubPath", expectedMountPath: "/claimWithSubPath", expectedSubPath: "mySubPath"},
"HostPathMount": {values: &values, volumeToTest: "hostpath-data", expectedMountPath: "/data"},
"HostPathMountWithSubPath": {values: &values, volumeToTest: "hostpath-dev", expectedMountPath: "/dev", expectedSubPath: "mySubPath"},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, nil, tc.values)
if err != nil {
suite.FailNow(err.Error())
}
deploymentManifest := suite.Chart.Manifests.Get("Deployment", "common-test")
suite.Assertions.NotEmpty(deploymentManifest)
containers := deploymentManifest.Path("spec.template.spec.containers").Children()
containerVolumeMounts := containers[0].Path("volumeMounts").Children()
suite.Assertions.NotEmpty(containerVolumeMounts)
for _, volumeMount := range containerVolumeMounts {
volumeMountName := volumeMount.Path("name").Data().(string)
if volumeMountName == tc.volumeToTest {
suite.Assertions.EqualValues(tc.expectedMountPath, volumeMount.Path("mountPath").Data())
if tc.expectedSubPath == "" {
suite.Assertions.Empty(volumeMount.Path("subPath").Data())
} else {
suite.Assertions.EqualValues(tc.expectedSubPath, volumeMount.Path("subPath").Data())
}
break
}
}
})
}
}
@@ -1,59 +0,0 @@
package common
import (
"testing"
"github.com/truecharts/apps/tests/helmunit"
"github.com/stretchr/testify/suite"
)
type ControllerTestSuite struct {
suite.Suite
Chart helmunit.HelmChart
}
func (suite *ControllerTestSuite) SetupSuite() {
suite.Chart = helmunit.New("common-test", "../../common-test")
suite.Chart.UpdateDependencies()
}
// We need this function to kick off the test suite, otherwise
// "go test" won't know about our tests
func TestController(t *testing.T) {
suite.Run(t, new(ControllerTestSuite))
}
func (suite *ControllerTestSuite) TestTypes() {
tests := map[string]struct {
values []string
expectedRenderFailure bool
expectedController string
}{
"Default": {values: nil, expectedRenderFailure: false, expectedController: "deployment"},
"DaemonSet": {values: []string{"controller.type=daemonset"}, expectedRenderFailure: false, expectedController: "daemonset"},
"Deployment": {values: []string{"controller.type=deployment"}, expectedRenderFailure: false, expectedController: "deployment"},
"StatefulSet": {values: []string{"controller.type=statefulset"}, expectedRenderFailure: false, expectedController: "statefulset"},
"Custom": {values: []string{"controller.type=custom"}, expectedRenderFailure: true, expectedController: ""},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, nil)
if tc.expectedRenderFailure {
suite.Assertions.Error(err)
return
}
if err != nil {
suite.FailNow(err.Error())
}
manifest := suite.Chart.Manifests.Get(tc.expectedController, "common-test")
suite.Assertions.NotEmpty(manifest)
types := map[string]interface{}{"deployment": nil, "statefulset": nil, "daemonset": nil}
delete(types, tc.expectedController)
for k := range types {
suite.Assertions.Empty(suite.Chart.Manifests.Get(k, "common-test"))
}
})
}
}
@@ -1,107 +0,0 @@
package common
import (
"testing"
"github.com/truecharts/apps/tests/helmunit"
"github.com/stretchr/testify/suite"
)
type HorizontalPodAutoscalerTestSuite struct {
suite.Suite
Chart helmunit.HelmChart
}
func (suite *HorizontalPodAutoscalerTestSuite) SetupSuite() {
suite.Chart = helmunit.New("common-test", "../../common-test")
suite.Chart.UpdateDependencies()
}
// We need this function to kick off the test suite, otherwise
// "go test" won't know about our tests
func TestHorizontalPodAutoscaler(t *testing.T) {
suite.Run(t, new(HorizontalPodAutoscalerTestSuite))
}
func (suite *HorizontalPodAutoscalerTestSuite) TestValues() {
baseValues := []string{"autoscaling.enabled=true"}
tests := map[string]struct {
values []string
expectedHorizontalPodAutoscaler bool
expectedTarget string
expectedMinReplicas int
expectedMaxReplicas int
}{
"Default": {
values: nil,
expectedHorizontalPodAutoscaler: false,
},
"Enabled": {
values: baseValues,
expectedHorizontalPodAutoscaler: true, expectedTarget: "common-test", expectedMinReplicas: 1, expectedMaxReplicas: 3,
},
"CustomSettings": {
values: append(baseValues, "autoscaling.target=common-custom", "autoscaling.minReplicas=4", "autoscaling.maxReplicas=8"),
expectedHorizontalPodAutoscaler: true, expectedTarget: "common-custom", expectedMinReplicas: 4, expectedMaxReplicas: 8,
},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, nil)
if err != nil {
suite.FailNow(err.Error())
}
manifest := suite.Chart.Manifests.Get("HorizontalPodAutoscaler", "common-test")
if tc.expectedHorizontalPodAutoscaler {
suite.Assertions.NotEmpty(manifest)
suite.Assertions.EqualValues(tc.expectedTarget, manifest.Path("spec.scaleTargetRef.name").Data())
suite.Assertions.EqualValues(tc.expectedMinReplicas, manifest.Path("spec.minReplicas").Data())
suite.Assertions.EqualValues(tc.expectedMaxReplicas, manifest.Path("spec.maxReplicas").Data())
} else {
suite.Assertions.Empty(manifest)
}
})
}
}
func (suite *HorizontalPodAutoscalerTestSuite) TestMetrics() {
baseValues := []string{"autoscaling.enabled=true"}
tests := map[string]struct {
values []string
expectedResources map[string]int
}{
"targetCPUUtilizationPercentage": {
values: append(baseValues, "autoscaling.targetCPUUtilizationPercentage=60"),
expectedResources: map[string]int{"cpu": 60},
},
"targetMemoryUtilizationPercentage": {
values: append(baseValues, "autoscaling.targetMemoryUtilizationPercentage=70"),
expectedResources: map[string]int{"memory": 70},
},
"Combined": {
values: append(baseValues, "autoscaling.targetCPUUtilizationPercentage=60", "autoscaling.targetMemoryUtilizationPercentage=70"),
expectedResources: map[string]int{"cpu": 60, "memory": 70},
},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, nil)
if err != nil {
suite.FailNow(err.Error())
}
manifest := suite.Chart.Manifests.Get("HorizontalPodAutoscaler", "common-test")
suite.Assertions.NotEmpty(manifest)
manifestMetrics := manifest.Path("spec.metrics").Children()
metricsMap := make(map[string]int)
for _, manifestMetric := range manifestMetrics {
metricsMap[manifestMetric.Path("resource.name").Data().(string)] = int(manifestMetric.Path("resource.targetAverageUtilization").Data().(float64))
}
suite.Assertions.EqualValues(tc.expectedResources, metricsMap)
})
}
}
-223
View File
@@ -1,223 +0,0 @@
package common
import (
"testing"
"github.com/truecharts/apps/tests/helmunit"
"github.com/stretchr/testify/suite"
)
type IngressTestSuite struct {
suite.Suite
Chart helmunit.HelmChart
}
func (suite *IngressTestSuite) SetupSuite() {
suite.Chart = helmunit.New("common-test", "../../common-test")
suite.Chart.UpdateDependencies()
}
// We need this function to kick off the test suite, otherwise
// "go test" won't know about our tests
func TestIngress(t *testing.T) {
suite.Run(t, new(IngressTestSuite))
}
func (suite *IngressTestSuite) TestValues() {
tests := map[string]struct {
values []string
expectedIngress bool
expectedHostName string
expectedPath string
}{
"Default": {
values: nil,
expectedIngress: false,
},
"Disabled": {
values: []string{"ingress.main.enabled=false"},
expectedIngress: false,
},
"CustomHostAndPath": {
values: []string{
"ingress.main.enabled=true",
"ingress.main.hosts[0].host=chart-test.local",
"ingress.main.hosts[0].paths[0].path=/test",
},
expectedIngress: true,
expectedHostName: "chart-test.local",
expectedPath: "/test",
},
"Multiple": {
values: []string{
"ingress.main.enabled=true",
"ingress.secondary.enabled=true",
},
expectedIngress: true,
},
"PathTemplate": {
values: []string{
"ingress.main.enabled=true",
"ingress.main.hosts[0].host=chart-example.local",
`ingress.main.hosts[0].paths[0].path=\{\{ .Release.Name \}\}.path`,
},
expectedIngress: true,
expectedPath: "common-test.path",
},
"HostTemplate": {
values: []string{
"ingress.main.enabled=true",
`ingress.main.hosts[0].host=\{\{ .Release.Name \}\}.hostname`,
"ingress.main.hosts[0].paths[0].path=/",
},
expectedIngress: true,
expectedHostName: "common-test.hostname",
},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, nil)
if err != nil {
suite.FailNow(err.Error())
}
ingressManifest := suite.Chart.Manifests.Get("Ingress", "common-test")
if tc.expectedIngress {
suite.Assertions.NotEmpty(ingressManifest)
ingressRules := ingressManifest.Path("spec.rules").Children()
if tc.expectedHostName != "" {
suite.Assertions.EqualValues(tc.expectedHostName, ingressRules[0].Path("host").Data())
}
if tc.expectedPath != "" {
paths := ingressRules[0].Path("http.paths").Children()
suite.Assertions.EqualValues(tc.expectedPath, paths[0].Path("path").Data())
}
} else {
suite.Assertions.Empty(ingressManifest)
}
})
}
}
func (suite *IngressTestSuite) TestPathServices() {
tests := map[string]struct {
values []string
expectedServiceName string
expectedServicePort int
}{
"Default": {
values: []string{"ingress.main.enabled=true"},
expectedServiceName: "common-test",
expectedServicePort: 8080,
},
"CustomService": {
values: []string{
"service.main.ports.http.targetPort=80",
"ingress.main.enabled=true",
"ingress.main.hosts[0].host=test.local",
"ingress.main.hosts[0].paths[0].path=/second/",
"ingress.main.hosts[0].paths[0].service.name=pathService",
"ingress.main.hosts[0].paths[0].service.port=1234",
},
expectedServiceName: "pathService",
expectedServicePort: 1234,
},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, nil)
if err != nil {
suite.FailNow(err.Error())
}
ingressManifest := suite.Chart.Manifests.Get("Ingress", "common-test")
suite.Assertions.NotEmpty(ingressManifest)
ingressRules := ingressManifest.Path("spec.rules").Children()
paths := ingressRules[0].Path("http.paths").Children()
primaryPath := paths[0]
if tc.expectedServiceName == "" {
suite.Assertions.Empty(primaryPath.Path("backend.service.name").Data())
} else {
suite.Assertions.EqualValues(tc.expectedServiceName, primaryPath.Path("backend.service.name").Data())
}
if tc.expectedServicePort == 0 {
suite.Assertions.Empty(primaryPath.Path("backend.service.port.number").Data())
} else {
suite.Assertions.EqualValues(tc.expectedServicePort, primaryPath.Path("backend.service.port.number").Data())
}
})
}
}
func (suite *IngressTestSuite) TestTLS() {
tests := map[string]struct {
values []string
expectedTLS bool
expectedHostName string
expectedSecretName string
}{
"Default": {
values: nil,
expectedTLS: false,
},
"Provided": {
values: []string{
"ingress.main.enabled=true",
"ingress.main.tls[0].hosts[0]=hostname",
"ingress.main.tls[0].secretName=secret-name",
},
expectedTLS: true,
expectedHostName: "hostname",
expectedSecretName: "secret-name",
},
"NoSecret": {
values: []string{
"ingress.main.enabled=true",
"ingress.main.tls[0].hosts[0]=hostname",
},
expectedTLS: true,
expectedHostName: "hostname",
expectedSecretName: "",
},
"SecretTemplate": {
values: []string{
"ingress.main.enabled=true",
"ingress.main.tls[0].hosts[0]=hostname",
`ingress.main.tls[0].secretName=\{\{ .Release.Name \}\}-secret`,
},
expectedTLS: true,
expectedHostName: "hostname",
expectedSecretName: "common-test-secret",
},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, nil)
if err != nil {
suite.FailNow(err.Error())
}
ingressManifest := suite.Chart.Manifests.Get("Ingress", "common-test")
if tc.expectedTLS {
suite.Assertions.NotEmpty(ingressManifest.Path("spec.tls").Data())
tlsSpec := ingressManifest.Path("spec.tls").Children()
tlsHostsSpec := tlsSpec[0].Path("hosts").Children()
suite.Assertions.EqualValues(tc.expectedHostName, tlsHostsSpec[0].Data())
if tc.expectedSecretName == "" {
suite.Assertions.Empty(tlsSpec[0].Path("secretName").Data())
} else {
suite.Assertions.EqualValues(tc.expectedSecretName, tlsSpec[0].Path("secretName").Data())
}
} else {
suite.Assertions.Empty(ingressManifest.Path("spec.tls").Data())
}
})
}
}
@@ -1,168 +0,0 @@
package common
import (
"testing"
"github.com/truecharts/apps/tests/helmunit"
"github.com/stretchr/testify/suite"
)
type PersistenceVolumeClaimTestSuite struct {
suite.Suite
Chart helmunit.HelmChart
}
func (suite *PersistenceVolumeClaimTestSuite) SetupSuite() {
suite.Chart = helmunit.New("common-test", "../../common-test")
suite.Chart.UpdateDependencies()
}
// We need this function to kick off the test suite, otherwise
// "go test" won't know about our tests
func TestPersistenceVolumeClaim(t *testing.T) {
suite.Run(t, new(PersistenceVolumeClaimTestSuite))
}
func (suite *PersistenceVolumeClaimTestSuite) TestName() {
tests := map[string]struct {
values []string
expectedName string
}{
"Default": {values: []string{"persistence.config.enabled=true"}, expectedName: "common-test-config"},
"WithoutSuffix": {values: []string{"persistence.config.enabled=true", "persistence.config.nameOverride=-"}, expectedName: "common-test"},
"WithNameOverride": {values: []string{"persistence.config.enabled=true", "persistence.config.nameOverride=custom"}, expectedName: "common-test-custom"},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, nil)
if err != nil {
suite.FailNow(err.Error())
}
pvcManifest := suite.Chart.Manifests.Get("PersistentVolumeClaim", tc.expectedName)
suite.Assertions.NotEmpty(pvcManifest)
})
}
}
func (suite *PersistenceVolumeClaimTestSuite) TestStorageClass() {
tests := map[string]struct {
values []string
expectedStorageClass string
}{
"Default": {values: []string{"persistence.config.enabled=true"}, expectedStorageClass: "-"},
"CustomClass": {values: []string{"persistence.config.enabled=true", "persistence.config.storageClass=custom"}, expectedStorageClass: "custom"},
"ScaleZFS": {values: []string{"persistence.config.enabled=true", "persistence.config.storageClass=SCALE-ZFS"}, expectedStorageClass: "ix-storage-class-common-test"},
"Empty": {values: []string{"persistence.config.enabled=true", "persistence.config.storageClass=-"}, expectedStorageClass: ""},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, nil)
if err != nil {
suite.FailNow(err.Error())
}
pvcManifest := suite.Chart.Manifests.Get("PersistentVolumeClaim", "common-test-config")
suite.Assertions.NotEmpty(pvcManifest)
if tc.expectedStorageClass == "-" {
suite.Assertions.Empty(pvcManifest.Path("spec.storageClassName").Data())
} else {
suite.Assertions.EqualValues(tc.expectedStorageClass, pvcManifest.Path("spec.storageClassName").Data())
}
})
}
}
func (suite *PersistenceVolumeClaimTestSuite) TestMetaData() {
defaultChartAnnotations := make(map[string]interface{})
defaultChartLabels := map[string]interface{}{
"app.kubernetes.io/instance": "common-test",
"app.kubernetes.io/managed-by": "Helm",
"app.kubernetes.io/name": "common-test",
"app.kubernetes.io/version":"1.6.1",
"helm.sh/chart": "common-test-3.1.4",
}
tests := map[string]struct {
values []string
expectedAnnotations map[string]interface{}
expectedLabels map[string]interface{}
}{
"Default": {
values: []string{
"persistence.config.enabled=true",
},
expectedAnnotations: nil,
expectedLabels: nil,
},
"NoRetain": {
values: []string{
"persistence.config.enabled=true",
"persistence.config.labels.test_label=test",
"persistence.config.annotations.test_annotation=test",
},
expectedAnnotations: map[string]interface{}{
"test_annotation": "test",
},
expectedLabels: map[string]interface{}{
"test_label": "test",
},
},
"Retain": {
values: []string{
"persistence.config.enabled=true",
"persistence.config.retain=true",
"persistence.config.labels.test_label=test",
"persistence.config.annotations.test_annotation=test",
},
expectedAnnotations: map[string]interface{}{
"helm.sh/resource-policy": "keep",
"test_annotation": "test",
},
expectedLabels: map[string]interface{}{
"test_label": "test",
},
},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, nil)
if err != nil {
suite.FailNow(err.Error())
}
pvcManifest := suite.Chart.Manifests.Get("PersistentVolumeClaim", "common-test-config")
suite.Assertions.NotEmpty(pvcManifest)
pvcAnnotations := pvcManifest.Path("metadata.annotations").Data()
testAnnotations := make(map[string]interface{})
for index, element := range defaultChartAnnotations {
testAnnotations[index] = element
}
for index, element := range tc.expectedAnnotations {
testAnnotations[index] = element
}
if len(testAnnotations) == 0 {
suite.Assertions.Equal(nil, pvcAnnotations)
} else {
suite.Assertions.EqualValues(testAnnotations, pvcAnnotations)
}
pvcLabels := pvcManifest.Path("metadata.labels").Data()
testLabels := make(map[string]interface{})
for index, element := range defaultChartLabels {
testLabels[index] = element
}
for index, element := range tc.expectedLabels {
testLabels[index] = element
}
if len(testLabels) == 0 {
suite.Assertions.Equal(nil, pvcLabels)
} else {
suite.Assertions.EqualValues(testLabels, pvcLabels)
}
})
}
}
-362
View File
@@ -1,362 +0,0 @@
package common
import (
"testing"
"github.com/truecharts/apps/tests/helmunit"
"github.com/stretchr/testify/suite"
)
type PodTestSuite struct {
suite.Suite
Chart helmunit.HelmChart
}
func (suite *PodTestSuite) SetupSuite() {
suite.Chart = helmunit.New("common-test", "../../common-test")
suite.Chart.UpdateDependencies()
}
// We need this function to kick off the test suite, otherwise
// "go test" won't know about our tests
func TestPod(t *testing.T) {
suite.Run(t, new(PodTestSuite))
}
func (suite *PodTestSuite) TestReplicas() {
tests := map[string]struct {
values []string
expectedValue interface{}
}{
"Default": {values: nil, expectedValue: 1},
"Specified": {values: []string{"controller.replicas=3"}, expectedValue: 3},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, nil)
if err != nil {
suite.FailNow(err.Error())
}
deploymentManifest := suite.Chart.Manifests.Get("Deployment", "common-test")
suite.Assertions.NotEmpty(deploymentManifest)
suite.Assertions.EqualValues(tc.expectedValue, deploymentManifest.Path("spec.replicas").Data())
})
}
}
func (suite *PodTestSuite) TestHostNetwork() {
tests := map[string]struct {
values []string
expectedValue interface{}
}{
"Default": {values: nil, expectedValue: nil},
"SpecifiedTrue": {values: []string{"hostNetwork=true"}, expectedValue: true},
"SpecifiedFalse": {values: []string{"hostNetwork=false"}, expectedValue: nil},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, nil)
if err != nil {
suite.FailNow(err.Error())
}
deploymentManifest := suite.Chart.Manifests.Get("Deployment", "common-test")
suite.Assertions.NotEmpty(deploymentManifest)
suite.Assertions.EqualValues(tc.expectedValue, deploymentManifest.Path("spec.template.spec.hostNetwork").Data())
})
}
}
func (suite *PodTestSuite) TestDnsPolicy() {
tests := map[string]struct {
values []string
expectedValue interface{}
}{
"Default": {values: nil, expectedValue: "ClusterFirst"},
"HostnetworkFalse": {values: []string{"hostNetwork=false"}, expectedValue: "ClusterFirst"},
"HostnetworkTrue": {values: []string{"hostNetwork=true"}, expectedValue: "ClusterFirstWithHostNet"},
"ManualOverride": {values: []string{"dnsPolicy=None"}, expectedValue: "None"},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, nil)
if err != nil {
suite.FailNow(err.Error())
}
deploymentManifest := suite.Chart.Manifests.Get("Deployment", "common-test")
suite.Assertions.NotEmpty(deploymentManifest)
suite.Assertions.EqualValues(tc.expectedValue, deploymentManifest.Path("spec.template.spec.dnsPolicy").Data())
})
}
}
func (suite *PodTestSuite) TestAdditionalContainers() {
tests := map[string]struct {
values []string
expectedContainer interface{}
}{
"Static": {values: []string{"additionalContainers[0].name=template-test"}, expectedContainer: "template-test"},
"DynamicTemplate": {values: []string{`additionalContainers[0].name=\{\{ .Release.Name \}\}-container`}, expectedContainer: "common-test-container"},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, nil)
if err != nil {
suite.FailNow(err.Error())
}
deploymentManifest := suite.Chart.Manifests.Get("Deployment", "common-test")
containers := deploymentManifest.Path("spec.template.spec.containers")
suite.Assertions.Contains(containers.Search("*", "name").Data(), tc.expectedContainer)
})
}
}
func (suite *PodTestSuite) TestPersistenceItems() {
values := `
persistence:
cache:
enabled: true
type: emptyDir
config:
enabled: true
data:
enabled: true
existingClaim: dataClaim
custom-mount:
enabled: true
type: custom
volumeSpec:
downwardAPI:
items:
- path: "labels"
fieldRef:
fieldPath: metadata.labels
`
tests := map[string]struct {
values *string
expectedVolumes []string
}{
"Default": {values: nil, expectedVolumes: []string{"shared"}},
"MultipleItems": {values: &values, expectedVolumes: []string{"config", "cache", "data", "custom-mount"}},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, nil, tc.values)
if err != nil {
suite.FailNow(err.Error())
}
deploymentManifest := suite.Chart.Manifests.Get("Deployment", "common-test")
volumes := deploymentManifest.Path("spec.template.spec.volumes")
if tc.expectedVolumes == nil {
suite.Assertions.EqualValues(nil, volumes.Data())
} else {
suite.Assertions.NotEmpty(volumes)
searchVolumes := volumes.Search("*", "name").Data()
for _, expectedVolume := range tc.expectedVolumes {
suite.Assertions.Contains(searchVolumes, expectedVolume)
}
}
})
}
}
func (suite *PodTestSuite) TestPersistenceClaimNames() {
values := `
persistence:
config:
enabled: true
existingClaim:
enabled: true
existingClaim: myClaim
claimWithoutSuffix:
enabled: true
nameOverride: "-"
accessMode: ReadWriteMany
size: 1G
claimWithNameOverride:
enabled: true
nameOverride: suffix
accessMode: ReadWriteMany
size: 1G
`
tests := map[string]struct {
values *string
volumeToTest string
expectedClaimName string
}{
"DefaultClaimName": {values: &values, volumeToTest: "config", expectedClaimName: "common-test-config"},
"ClaimNameWithoutSuffix": {values: &values, volumeToTest: "claimWithoutSuffix", expectedClaimName: "common-test"},
"ClaimNameWithNameOverride": {values: &values, volumeToTest: "claimWithNameOverride", expectedClaimName: "common-test-suffix"},
"ExistingClaim": {values: &values, volumeToTest: "existingClaim", expectedClaimName: "myClaim"},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, nil, tc.values)
if err != nil {
suite.FailNow(err.Error())
}
deploymentManifest := suite.Chart.Manifests.Get("Deployment", "common-test")
volumes := deploymentManifest.Path("spec.template.spec.volumes").Children()
for _, volume := range volumes {
volumeName := volume.Path("name").Data().(string)
if volumeName == tc.volumeToTest {
suite.Assertions.EqualValues(tc.expectedClaimName, volume.Path("persistentVolumeClaim.claimName").Data())
break
}
}
})
}
}
func (suite *PodTestSuite) TestPersistenceEmptyDir() {
baseValues := `
persistence:
config:
enabled: true
type: emptyDir
`
tests := map[string]struct {
values []string
expectedMedium string
expectedSizeLimit string
}{
"Enabled": {values: nil, expectedMedium: "", expectedSizeLimit: ""},
"WithMedium": {values: []string{"persistence.config.medium=memory"}, expectedMedium: "memory", expectedSizeLimit: ""},
"WithSizeLimit": {values: []string{"persistence.config.medium=memory", "persistence.config.sizeLimit=1Gi"}, expectedMedium: "memory", expectedSizeLimit: "1Gi"},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, &baseValues)
if err != nil {
suite.FailNow(err.Error())
}
deploymentManifest := suite.Chart.Manifests.Get("Deployment", "common-test")
volumes := deploymentManifest.Path("spec.template.spec.volumes").Children()
volume := volumes[0]
suite.Assertions.NotEmpty(volume.Data())
if tc.expectedMedium == "" {
suite.Assertions.Nil(volume.Path("emptyDir.medium"))
} else {
suite.Assertions.EqualValues(tc.expectedMedium, volume.Path("emptyDir.medium").Data())
}
if tc.expectedSizeLimit == "" {
suite.Assertions.Nil(volume.Path("emptyDir.sizeLimit"))
} else {
suite.Assertions.EqualValues(tc.expectedSizeLimit, volume.Path("emptyDir.sizeLimit").Data())
}
})
}
}
func (suite *PodTestSuite) TestHostPathVolumes() {
values := `
persistence:
hostpathmounts-data:
enabled: true
type: hostPath
hostPath: "/tmp1"
mountPath: "/data"
hostpathmounts-with-type:
enabled: true
type: hostPath
hostPath: "/tmp2"
hostPathType: "Directory"
mountPath: "/data2"
`
tests := map[string]struct {
values *string
expectedVolumes []string
}{
"Default": {values: nil, expectedVolumes: []string{"shared"}},
"MultipleItems": {values: &values, expectedVolumes: []string{"hostpathmounts-data", "hostpathmounts-with-type"}},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, nil, tc.values)
if err != nil {
suite.FailNow(err.Error())
}
deploymentManifest := suite.Chart.Manifests.Get("Deployment", "common-test")
volumes := deploymentManifest.Path("spec.template.spec.volumes")
if tc.expectedVolumes == nil {
suite.Assertions.EqualValues(nil, volumes.Data())
} else {
suite.Assertions.NotEmpty(volumes)
searchVolumes := volumes.Search("*", "name").Data()
for _, expectedVolume := range tc.expectedVolumes {
suite.Assertions.Contains(searchVolumes, expectedVolume)
}
}
})
}
}
func (suite *PodTestSuite) TestVolumeClaimTemplates() {
values := `
volumeClaimTemplates:
- name: 'storage'
accessMode: 'ReadWriteOnce'
size: '10Gi'
storageClass: 'storage'
`
tests := map[string]struct {
values []string
volumeClaimToTest string
expectedAccessMode string
expectedSize string
expectedStorageClassName string
}{
"StatefulSet": {values: []string{"controller.type=statefulset"}, volumeClaimToTest: "storage", expectedAccessMode: "ReadWriteOnce", expectedSize: "10Gi", expectedStorageClassName: "storage"},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, &values)
if err != nil {
suite.FailNow(err.Error())
}
controllerManifest := suite.Chart.Manifests.Get("StatefulSet", "common-test")
suite.Assertions.NotEmpty(controllerManifest)
volumeClaimTemplates := controllerManifest.Path("spec.volumeClaimTemplates").Children()
suite.Assertions.NotEmpty(volumeClaimTemplates)
for _, volumeClaimTemplate := range volumeClaimTemplates {
volumeClaimName := volumeClaimTemplate.Path("metadata.name").Data()
if volumeClaimName == tc.volumeClaimToTest {
if tc.expectedAccessMode == "" {
suite.Assertions.Empty(controllerManifest)
} else {
accessModes := volumeClaimTemplate.Path("spec.accessModes").Children()
suite.Assertions.EqualValues(tc.expectedAccessMode, accessModes[0].Data())
}
if tc.expectedSize == "" {
suite.Assertions.Empty(controllerManifest)
} else {
suite.Assertions.EqualValues(tc.expectedSize, volumeClaimTemplate.Path("spec.resources.requests.storage").Data())
}
if tc.expectedStorageClassName == "" {
suite.Assertions.Empty(controllerManifest)
} else {
suite.Assertions.EqualValues(tc.expectedStorageClassName, volumeClaimTemplate.Path("spec.storageClassName").Data())
}
break
}
}
})
}
}
-103
View File
@@ -1,103 +0,0 @@
package common
import (
"testing"
"github.com/truecharts/apps/tests/helmunit"
"github.com/stretchr/testify/suite"
)
type ServiceTestSuite struct {
suite.Suite
Chart helmunit.HelmChart
}
func (suite *ServiceTestSuite) SetupSuite() {
suite.Chart = helmunit.New("common-test", "../../common-test")
suite.Chart.UpdateDependencies()
}
// We need this function to kick off the test suite, otherwise
// "go test" won't know about our tests
func TestService(t *testing.T) {
suite.Run(t, new(ServiceTestSuite))
}
func (suite *ServiceTestSuite) TestServiceName() {
tests := map[string]struct {
values []string
expectedName string
}{
"Default": {values: nil, expectedName: "common-test"},
"CustomName": {values: []string{"service.main.nameOverride=main"}, expectedName: "common-test-main"},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, nil)
if err != nil {
suite.FailNow(err.Error())
}
serviceManifest := suite.Chart.Manifests.Get("Service", tc.expectedName)
suite.Assertions.NotEmpty(serviceManifest)
})
}
}
func (suite *ServiceTestSuite) TestPortNames() {
tests := map[string]struct {
values []string
expectedRenderFailure bool
expectedName string
expectedTargetPort interface{}
}{
"Default": {values: nil, expectedRenderFailure: false, expectedName: "main", expectedTargetPort: "main"},
"CustomName": {values: []string{"service.main.ports.main.enabled=false", "service.main.ports.server.enabled=true", "service.main.ports.server.port=8080"}, expectedRenderFailure: false, expectedName: "server", expectedTargetPort: "server"},
"CustomTargetPort": {values: []string{"service.main.ports.main.targetPort=80"}, expectedRenderFailure: false, expectedName: "main", expectedTargetPort: 80},
"NamedTargetPort": {values: []string{"service.main.ports.main.targetPort=name"}, expectedRenderFailure: true, expectedName: "", expectedTargetPort: nil},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, nil)
if tc.expectedRenderFailure {
suite.Assertions.Error(err)
return
}
if err != nil {
suite.FailNow(err.Error())
}
serviceManifest := suite.Chart.Manifests.Get("Service", "common-test")
suite.Assertions.NotEmpty(serviceManifest)
servicePorts := serviceManifest.Path("spec.ports").Children()
suite.Assertions.EqualValues(tc.expectedName, servicePorts[0].Path("name").Data())
suite.Assertions.EqualValues(tc.expectedTargetPort, servicePorts[0].Path("targetPort").Data())
})
}
}
func (suite *ServiceTestSuite) TestPortProtocol() {
tests := map[string]struct {
values []string
expectedProtocol string
}{
"Default": {values: nil, expectedProtocol: "TCP"},
"ExplicitTCP": {values: []string{"service.main.ports.main.protocol=TCP"}, expectedProtocol: "TCP"},
"ExplicitHTTP": {values: []string{"service.main.ports.main.protocol=HTTP"}, expectedProtocol: "TCP"},
"ExplicitHTTPS": {values: []string{"service.main.ports.main.protocol=HTTPS"}, expectedProtocol: "TCP"},
"ExplicitUDP": {values: []string{"service.main.ports.main.protocol=UDP"}, expectedProtocol: "UDP"},
}
for name, tc := range tests {
suite.Suite.Run(name, func() {
err := suite.Chart.Render(nil, tc.values, nil)
if err != nil {
suite.FailNow(err.Error())
}
serviceManifest := suite.Chart.Manifests.Get("Service", "common-test")
suite.Assertions.NotEmpty(serviceManifest)
servicePorts := serviceManifest.Path("spec.ports").Children()
suite.Assertions.EqualValues(tc.expectedProtocol, servicePorts[0].Path("protocol").Data())
})
}
}
+2 -2
View File
@@ -688,8 +688,8 @@ resources:
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
limits:
cpu: 2000m
memory: 2Gi
cpu: 4000m
memory: 8Gi
requests:
cpu: 10m
memory: 50Mi
@@ -5,15 +5,16 @@ class Test < ChartTest
@@chart = Chart.new('charts/library/common-test')
describe @@chart.name do
describe 'job::permissions' do
it 'no job exists by default' do
job = chart.resources(kind: "Job").first
assert_nil(job)
describe 'initContainer::permissions' do
it 'initContainer exists by default' do
deployment = chart.resources(kind: "Deployment").first
initContainer = deployment["spec"]["template"]["spec"]["initContainers"][0]
refute_nil(initContainer)
end
it 'hostPathMounts do not affect permissions job by default' do
it 'persistenceList do not affect permissions job by default' do
values = {
hostPathMounts: [
persistenceList: [
{
name: "data",
enabled: true,
@@ -23,13 +24,12 @@ class Test < ChartTest
]
}
chart.value values
job = chart.resources(kind: "Job").first
assert_nil(job["spec"]["template"]["spec"]["volumes"])
assert_nil(job["spec"]["template"]["spec"]["containers"][0]["volumeMounts"])
deployment = chart.resources(kind: "Deployment").first
assert_nil(deployment["spec"]["template"]["spec"]["initContainers"][0]["volumeMounts"])
end
it 'hostPathMounts.setPermissions adds volume(mounts)' do
it 'persistenceList.setPermissions adds volume(mounts)' do
values = {
hostPathMounts: [
persistenceList: [
{
name: "data",
enabled: true,
@@ -40,13 +40,13 @@ class Test < ChartTest
]
}
chart.value values
job = chart.resources(kind: "Job").first
assert_equal("hostpathmounts-data", job["spec"]["template"]["spec"]["volumes"][0]["name"])
assert_equal("hostpathmounts-data", job["spec"]["template"]["spec"]["containers"][0]["volumeMounts"][0]["name"])
deployment = chart.resources(kind: "Deployment").first
assert_equal("data", deployment["spec"]["template"]["spec"]["volumes"][0]["name"])
assert_equal("data", deployment["spec"]["template"]["spec"]["initContainers"][0]["volumeMounts"][0]["name"])
end
it 'supports multiple hostPathMounts' do
it 'supports multiple persistenceList' do
values = {
hostPathMounts: [
persistenceList: [
{
name: "data",
enabled: true,
@@ -55,28 +55,28 @@ class Test < ChartTest
hostPath: "/tmp"
},
{
name: "config",
name: "configlist",
enabled: true,
setPermissions: true,
mountPath: "/config",
mountPath: "/configlist",
hostPath: "/tmp"
}
]
}
chart.value values
job = chart.resources(kind: "Job").first
mainContainer = job["spec"]["template"]["spec"]["containers"][0]
deployment = chart.resources(kind: "Deployment").first
initContainer = deployment["spec"]["template"]["spec"]["initContainers"][0]
# Check that all hostPathMounts volumes have mounts
values[:hostPathMounts].each { |value|
volumeMount = mainContainer["volumeMounts"].find{ |v| v["name"] == "hostpathmounts-" + value[:name].to_s }
# Check that all persistenceList volumes have mounts
values[:persistenceList].each { |value|
volumeMount = initContainer["volumeMounts"].find{ |v| v["name"] == "" + value[:name].to_s }
refute_nil(volumeMount)
}
end
it 'supports setting mountPath' do
values = {
hostPathMounts: [
persistenceList: [
{
name: "data",
enabled: true,
@@ -87,107 +87,87 @@ class Test < ChartTest
]
}
chart.value values
job = chart.resources(kind: "Job").first
mainContainer = job["spec"]["template"]["spec"]["containers"][0]
deployment = chart.resources(kind: "Deployment").first
initContainer = deployment["spec"]["template"]["spec"]["initContainers"][0]
volumeMount = mainContainer["volumeMounts"].find{ |v| v["name"] == "hostpathmounts-data" }
volumeMount = initContainer["volumeMounts"].find{ |v| v["name"] == "data" }
refute_nil(volumeMount)
assert_equal("/data", volumeMount["mountPath"])
end
it 'could mount multiple volumes' do
values = {
hostPathMounts: [
persistenceList: [
{
name: "data",
enabled: true,
type: "hostPath",
setPermissions: true,
mountPath: "/data",
hostPath: "/tmp1"
},
{
name: "config",
name: "configlist",
enabled: true,
type: "hostPath",
setPermissions: true,
mountPath: "/config",
mountPath: "/configlist",
hostPath: "/tmp2"
}
]
}
chart.value values
job = chart.resources(kind: "Job").first
volumes = job["spec"]["template"]["spec"]["volumes"]
deployment = chart.resources(kind: "Deployment").first
volumes = deployment["spec"]["template"]["spec"]["volumes"]
volume = volumes.find{ |v| v["name"] == "hostpathmounts-data"}
volume = volumes.find{ |v| v["name"] == "data"}
refute_nil(volume)
assert_equal('/tmp1', volume["hostPath"]["path"])
volume = volumes.find{ |v| v["name"] == "hostpathmounts-config"}
volume = volumes.find{ |v| v["name"] == "configlist"}
refute_nil(volume)
assert_equal('/tmp2', volume["hostPath"]["path"])
end
it 'emptyDir can be enabled' do
values = {
hostPathMounts: [
{
name: "data",
enabled: true,
setPermissions: true,
emptyDir: true,
mountPath: "/data"
}
]
}
chart.value values
job = chart.resources(kind: "Job").first
volumes = job["spec"]["template"]["spec"]["volumes"]
volume = volumes.find{ |v| v["name"] == "hostpathmounts-data"}
refute_nil(volume)
assert_equal(Hash.new, volume["emptyDir"])
end
it 'can process default (568:568) permissions for multiple volumes' do
results= {
command: ["/bin/sh", "-c", "chown -R 568:568 /data
chown -R 568:568 /config
"]
command: ["/bin/sh", "-c", "echo 'Automatically correcting permissions...';chown -R :568 '/configlist'; chmod -R g+w '/configlist';chown -R :568 '/data'; chmod -R g+w '/data';"]
}
values = {
hostPathMounts: [
persistenceList: [
{
name: "data",
enabled: true,
type: "hostPath",
setPermissions: true,
mountPath: "/data",
hostPath: "/tmp1"
},
{
name: "config",
name: "configlist",
enabled: true,
type: "hostPath",
setPermissions: true,
mountPath: "/config",
mountPath: "/configlist",
hostPath: "/tmp2"
}
]
}
chart.value values
job = chart.resources(kind: "Job").first
mainContainer = job["spec"]["template"]["spec"]["containers"][0]
assert_equal(results[:command], mainContainer["command"])
deployment = chart.resources(kind: "Deployment").first
initContainer = deployment["spec"]["template"]["spec"]["initContainers"][0]
assert_equal(results[:command], initContainer["command"])
end
it 'outputs default permissions with irrelevant podSecurityContext' do
results= {
command: ["/bin/sh", "-c", "chown -R 568:568 /data
chown -R 568:568 /config
"]
command: ["/bin/sh", "-c", "echo 'Automatically correcting permissions...';chown -R :568 '/configlist'; chmod -R g+w '/configlist';chown -R :568 '/data'; chmod -R g+w '/data';"]
}
values = {
podSecurityContext: {
allowPrivilegeEscalation: false
allowPrivilegeEscalation: false
},
hostPathMounts: [
persistenceList: [
{
name: "data",
enabled: true,
@@ -196,31 +176,29 @@ chown -R 568:568 /config
hostPath: "/tmp1"
},
{
name: "config",
name: "configlist",
enabled: true,
setPermissions: true,
mountPath: "/config",
mountPath: "/configlist",
hostPath: "/tmp2"
}
]
}
chart.value values
job = chart.resources(kind: "Job").first
mainContainer = job["spec"]["template"]["spec"]["containers"][0]
assert_equal(results[:command], mainContainer["command"])
deployment = chart.resources(kind: "Deployment").first
initContainer = deployment["spec"]["template"]["spec"]["initContainers"][0]
assert_equal(results[:command], initContainer["command"])
end
it 'outputs fsgroup permissions for multiple volumes when set' do
results= {
command: ["/bin/sh", "-c", "chown -R 568:666 /data
chown -R 568:666 /config
"]
command: ["/bin/sh", "-c", "echo 'Automatically correcting permissions...';chown -R :666 '/configlist'; chmod -R g+w '/configlist';chown -R :666 '/data'; chmod -R g+w '/data';"]
}
values = {
podSecurityContext: {
fsGroup: 666
},
hostPathMounts: [
persistenceList: [
{
name: "data",
enabled: true,
@@ -229,31 +207,29 @@ chown -R 568:666 /config
hostPath: "/tmp1"
},
{
name: "config",
name: "configlist",
enabled: true,
setPermissions: true,
mountPath: "/config",
mountPath: "/configlist",
hostPath: "/tmp2"
}
]
}
chart.value values
job = chart.resources(kind: "Job").first
mainContainer = job["spec"]["template"]["spec"]["containers"][0]
assert_equal(results[:command], mainContainer["command"])
deployment = chart.resources(kind: "Deployment").first
initContainer = deployment["spec"]["template"]["spec"]["initContainers"][0]
assert_equal(results[:command], initContainer["command"])
end
it 'outputs runAsUser permissions for multiple volumes when set' do
results= {
command: ["/bin/sh", "-c", "chown -R 999:568 /data
chown -R 999:568 /config
"]
command: ["/bin/sh", "-c", "echo 'Automatically correcting permissions...';chown -R :568 '/configlist'; chmod -R g+w '/configlist';chown -R :568 '/data'; chmod -R g+w '/data';"]
}
values = {
podSecurityContext: {
runAsUser: 999
},
hostPathMounts: [
persistenceList: [
{
name: "data",
enabled: true,
@@ -262,32 +238,30 @@ chown -R 999:568 /config
hostPath: "/tmp1"
},
{
name: "config",
name: "configlist",
enabled: true,
setPermissions: true,
mountPath: "/config",
mountPath: "/configlist",
hostPath: "/tmp2"
}
]
}
chart.value values
job = chart.resources(kind: "Job").first
mainContainer = job["spec"]["template"]["spec"]["containers"][0]
assert_equal(results[:command], mainContainer["command"])
deployment = chart.resources(kind: "Deployment").first
initContainer = deployment["spec"]["template"]["spec"]["initContainers"][0]
assert_equal(results[:command], initContainer["command"])
end
it 'outputs fsGroup AND runAsUser permissions for multiple volumes when both are set' do
results= {
command: ["/bin/sh", "-c", "chown -R 999:666 /data
chown -R 999:666 /config
"]
command: ["/bin/sh", "-c", "echo 'Automatically correcting permissions...';chown -R :666 '/configlist'; chmod -R g+w '/configlist';chown -R :666 '/data'; chmod -R g+w '/data';"]
}
values = {
podSecurityContext: {
fsGroup: 666,
runAsUser: 999
},
hostPathMounts: [
persistenceList: [
{
name: "data",
enabled: true,
@@ -296,31 +270,29 @@ chown -R 999:666 /config
hostPath: "/tmp1"
},
{
name: "config",
name: "configlist",
enabled: true,
setPermissions: true,
mountPath: "/config",
mountPath: "/configlist",
hostPath: "/tmp2"
}
]
}
chart.value values
job = chart.resources(kind: "Job").first
mainContainer = job["spec"]["template"]["spec"]["containers"][0]
assert_equal(results[:command], mainContainer["command"])
deployment = chart.resources(kind: "Deployment").first
initContainer = deployment["spec"]["template"]["spec"]["initContainers"][0]
assert_equal(results[:command], initContainer["command"])
end
it 'outputs PUID AND PGID permissions for multiple volumes when both are set' do
results= {
command: ["/bin/sh", "-c", "chown -R 999:666 /data
chown -R 999:666 /config
"]
command: ["/bin/sh", "-c", "echo 'Automatically correcting permissions...';chown -R :568 '/configlist'; chmod -R g+w '/configlist';chown -R :568 '/data'; chmod -R g+w '/data';"]
}
values = {
env: {
PGID: 666,
PUID: 999
},
hostPathMounts: [
persistenceList: [
{
name: "data",
enabled: true,
@@ -329,18 +301,18 @@ chown -R 999:666 /config
hostPath: "/tmp1"
},
{
name: "config",
name: "configlist",
enabled: true,
setPermissions: true,
mountPath: "/config",
mountPath: "/configlist",
hostPath: "/tmp2"
}
]
}
chart.value values
job = chart.resources(kind: "Job").first
mainContainer = job["spec"]["template"]["spec"]["containers"][0]
assert_equal(results[:command], mainContainer["command"])
deployment = chart.resources(kind: "Deployment").first
initContainer = deployment["spec"]["template"]["spec"]["initContainers"][0]
assert_equal(results[:command], initContainer["command"])
end
end
end
+9 -9
View File
@@ -88,7 +88,7 @@ class Test < ChartTest
chart.value values
refute_nil(resource('Secret'))
secret = chart.resources(kind: "Secret").first
assert_equal("common-test-main-tls-0-ixcert-1", secret["metadata"]["name"])
assert_equal("common-test-tls-0-ixcert-1", secret["metadata"]["name"])
refute_nil(secret["data"]["tls.crt"])
refute_nil(secret["data"]["tls.key"])
end
@@ -166,13 +166,13 @@ class Test < ChartTest
chart.value values
refute_nil(resource('Secret'))
secret = chart.resources(kind: "Secret").first
assert_equal("common-test-main-tls-0-ixcert-1", secret["metadata"]["name"])
assert_equal("common-test-tls-0-ixcert-1", secret["metadata"]["name"])
refute_nil(secret["data"]["tls.crt"])
refute_nil(secret["data"]["tls.key"])
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test-main" }
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test" }
refute_nil(ingress)
assert_equal("common-test-main-tls-0-ixcert-1", ingress["spec"]["tls"][0]["secretName"])
assert_equal("common-test-tls-0-ixcert-1", ingress["spec"]["tls"][0]["secretName"])
end
it 'multiple tls sections generate multiple secrets' do
values = {
@@ -304,18 +304,18 @@ class Test < ChartTest
chart.value values
refute_nil(resource('Secret'))
secret1 = chart.resources(kind: "Secret").first
assert_equal("common-test-main-tls-0-ixcert-1", secret1["metadata"]["name"])
assert_equal("common-test-tls-0-ixcert-1", secret1["metadata"]["name"])
refute_nil(secret1["data"]["tls.crt"])
refute_nil(secret1["data"]["tls.key"])
secret2 = chart.resources(kind: "Secret").find{ |s| s["metadata"]["name"] == "common-test-main-tls-1-ixcert-2" }
secret2 = chart.resources(kind: "Secret").find{ |s| s["metadata"]["name"] == "common-test-tls-1-ixcert-2" }
refute_nil(secret2)
refute_nil(secret2["data"]["tls.crt"])
refute_nil(secret2["data"]["tls.key"])
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test-main" }
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test" }
refute_nil(ingress)
assert_equal("common-test-main-tls-0-ixcert-1", ingress["spec"]["tls"][0]["secretName"])
assert_equal("common-test-main-tls-1-ixcert-2", ingress["spec"]["tls"][1]["secretName"])
assert_equal("common-test-tls-0-ixcert-1", ingress["spec"]["tls"][0]["secretName"])
assert_equal("common-test-tls-1-ixcert-2", ingress["spec"]["tls"][1]["secretName"])
end
end
end
@@ -6,11 +6,11 @@ class Test < ChartTest
describe @@chart.name do
describe 'container::resources' do
it 'no resources added by default' do
it 'specific resources added by default' do
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
assert_equal({"limits"=>{}}, mainContainer["resources"])
assert_equal({"limits"=>{"cpu"=>"4000m", "memory"=>"8Gi"}, "requests"=>{"cpu"=>"10m", "memory"=>"50Mi"}}, mainContainer["resources"])
end
it 'resources can be added' do
values = {
@@ -22,7 +22,7 @@ class Test < ChartTest
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
assert_equal({"limits"=>{}, "testresourcename"=>"testresourcevalue"}, mainContainer["resources"])
assert_equal({"limits"=>{"cpu"=>"4000m", "memory"=>"8Gi"}, "requests"=>{"cpu"=>"10m", "memory"=>"50Mi"}, "testresourcename"=>"testresourcevalue"}, mainContainer["resources"])
end
it 'resources.limits can be added' do
values = {
@@ -36,7 +36,7 @@ class Test < ChartTest
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
assert_equal({"limits"=>{"testlimitkey"=>"testlimitvalue"}}, mainContainer["resources"])
assert_equal({"limits"=>{"cpu"=>"4000m", "memory"=>"8Gi", "testlimitkey"=>"testlimitvalue"}, "requests"=>{"cpu"=>"10m", "memory"=>"50Mi"}}, mainContainer["resources"])
end
it 'resources and resources.limits can both be added' do
values = {
@@ -51,7 +51,7 @@ class Test < ChartTest
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
assert_equal({"limits"=>{"testlimitkey"=>"testlimitvalue"}, "testresourcekey"=>"testresourcevalue"}, mainContainer["resources"])
assert_equal({"limits"=>{"cpu"=>"4000m", "memory"=>"8Gi", "testlimitkey"=>"testlimitvalue"}, "requests"=>{"cpu"=>"10m", "memory"=>"50Mi"}, "testresourcekey"=>"testresourcevalue"}, mainContainer["resources"])
end
end
describe 'container::resources-scaleGPU' do
@@ -65,7 +65,7 @@ class Test < ChartTest
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
assert_equal({"limits"=>{"intelblabla"=>1}}, mainContainer["resources"])
assert_equal({"limits"=>{"cpu"=>"4000m", "intelblabla"=>1, "memory"=>"8Gi"}, "requests"=>{"cpu"=>"10m", "memory"=>"50Mi"}}, mainContainer["resources"])
end
it 'scaleGPU can be combined with resources and resource values' do
values = {
@@ -83,7 +83,7 @@ class Test < ChartTest
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
assert_equal({"limits"=>{"intelblabla"=>1, "testlimitkey"=>"testlimitvalue"}, "testresourcekey"=>"testresourcevalue"}, mainContainer["resources"])
assert_equal({"limits"=>{"cpu"=>"4000m", "intelblabla"=>1, "memory"=>"8Gi", "testlimitkey"=>"testlimitvalue"}, "requests"=>{"cpu"=>"10m", "memory"=>"50Mi"}, "testresourcekey"=>"testresourcevalue"}, mainContainer["resources"])
end
end
end
+125 -229
View File
@@ -21,7 +21,7 @@ class Test < ChartTest
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
assert_equal(values[:command], mainContainer["command"])
assert_equal([values[:command]], mainContainer["command"])
end
it 'accepts a list of strings' do
@@ -55,7 +55,7 @@ class Test < ChartTest
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
assert_equal(values[:args], mainContainer["args"])
assert_equal([values[:args]], mainContainer["args"])
end
it 'accepts a list of strings' do
@@ -75,7 +75,12 @@ class Test < ChartTest
describe 'container::environment settings' do
it 'Check no environment variables' do
values = {}
values = {
securityContext: {
runAsNonRoot: false,
readOnlyRootFilesystem: false
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
@@ -83,67 +88,92 @@ class Test < ChartTest
assert_nil(mainContainer["env"])
end
it 'set "static" environment variables' do
it 'set static "k/v pair style" environment variables' do
values = {
env: {
STATIC_ENV: 'value_of_env',
TRUTHY_ENV: '0',
BOOL_ENV: false,
FLOAT_ENV: 4.2,
INT_ENV: 42,
STRING_ENV: 'value_of_env'
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
assert_equal(values[:env].keys[0].to_s, mainContainer["env"][0]["name"])
assert_equal(values[:env].values[0].to_s, mainContainer["env"][0]["value"])
assert_equal(values[:env].keys[1].to_s, mainContainer["env"][1]["name"])
assert_equal(values[:env].values[1].to_s, mainContainer["env"][1]["value"])
end
it 'set "list" of "static" environment variables' do
values = {
envList: [
{
name: 'STATIC_ENV_FROM_LIST',
value: 'STATIC_ENV_VALUE_FROM_LIST'
}
]
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
assert_equal(values[:envList][0][:name].to_s, mainContainer["env"][0]["name"])
assert_equal(values[:envList][0][:value].to_s, mainContainer["env"][0]["value"])
end
it 'set both "list" AND "dict" of "static" environment variables' do
values = {
env: {
STATIC_ENV: 'value_of_env'
},
envList: [
{
name: 'STATIC_ENV_FROM_LIST',
value: 'STATIC_ENV_VALUE_FROM_LIST'
}
]
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
assert_equal(values[:envList][0][:name].to_s, mainContainer["env"][0]["name"])
assert_equal(values[:envList][0][:value].to_s, mainContainer["env"][0]["value"])
assert_equal(values[:env].keys[0].to_s, mainContainer["env"][1]["name"])
assert_equal(values[:env].values[0].to_s, mainContainer["env"][1]["value"])
assert_equal(values[:env].keys[1].to_s, mainContainer["env"][2]["name"])
assert_equal(values[:env].values[1].to_s, mainContainer["env"][2]["value"])
assert_equal(values[:env].keys[2].to_s, mainContainer["env"][3]["name"])
assert_equal(values[:env].values[2].to_s, mainContainer["env"][3]["value"])
assert_equal(values[:env].keys[3].to_s, mainContainer["env"][4]["name"])
assert_equal(values[:env].values[3].to_s, mainContainer["env"][4]["value"])
end
it 'set "valueFrom" environment variables' do
it 'set list of static "kubernetes style" environment variables' do
values = {
envValueFrom: {
envList: [
{
name: 'STATIC_ENV_FROM_LIST',
value: 'STATIC_ENV_VALUE_FROM_LIST'
}
]
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
assert_equal(values[:envList][0][:name].to_s, mainContainer["env"][1]["name"])
assert_equal(values[:envList][0][:value].to_s, mainContainer["env"][1]["value"])
end
it 'set both static "k/v pair style" and static "k/valueFrom style" environment variables' do
values = {
env: {
STATIC_ENV: 'value_of_env',
STATIC_ENV_FROM: {
valueFrom: {
fieldRef: {
fieldPath: "spec.nodeName"
}
}
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
assert_equal(values[:env].keys[0].to_s, mainContainer["env"][1]["name"])
assert_equal(values[:env].values[0].to_s, mainContainer["env"][1]["value"])
assert_equal(values[:env].keys[1].to_s, mainContainer["env"][2]["name"])
assert_equal(values[:env].values[1][:valueFrom][:fieldRef][:fieldPath], mainContainer["env"][2]["valueFrom"]["fieldRef"]["fieldPath"])
end
it 'set static "k/explicitValueFrom pair style" environment variables' do
values = {
env: {
NODE_NAME: {
valueFrom: {
fieldRef: {
fieldPath: "spec.nodeName"
}
}
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
assert_equal(values[:env].keys[0].to_s, mainContainer["env"][1]["name"])
assert_equal(values[:env].values[0][:valueFrom][:fieldRef][:fieldPath], mainContainer["env"][1]["valueFrom"]["fieldRef"]["fieldPath"])
end
it 'set static "k/implicitValueFrom pair style" environment variables' do
values = {
env: {
NODE_NAME: {
fieldRef: {
fieldPath: "spec.nodeName"
@@ -155,16 +185,30 @@ class Test < ChartTest
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
assert_equal(values[:envValueFrom].keys[0].to_s, mainContainer["env"][0]["name"])
assert_equal(values[:envValueFrom].values[0][:fieldRef][:fieldPath], mainContainer["env"][0]["valueFrom"]["fieldRef"]["fieldPath"])
assert_equal(values[:env].keys[0].to_s, mainContainer["env"][1]["name"])
assert_equal(values[:env].values[0][:fieldRef][:fieldPath], mainContainer["env"][1]["valueFrom"]["fieldRef"]["fieldPath"])
end
it 'set "static" and "Dynamic/Tpl" environment variables' do
it 'set both static "k/v pair style" and templated "k/v pair style" environment variables' do
values = {
env: {
DYN_ENV: "{{ .Release.Name }}-admin",
STATIC_ENV: 'value_of_env'
},
envTpl: {
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
assert_equal(values[:env].keys[0].to_s, mainContainer["env"][1]["name"])
assert_equal("common-test-admin", mainContainer["env"][1]["value"])
assert_equal(values[:env].keys[1].to_s, mainContainer["env"][2]["name"])
assert_equal(values[:env].values[1].to_s, mainContainer["env"][2]["value"])
end
it 'set templated "k/v pair style" environment variables' do
values = {
env: {
DYN_ENV: "{{ .Release.Name }}-admin"
}
}
@@ -172,24 +216,41 @@ class Test < ChartTest
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
assert_equal(values[:env].keys[0].to_s, mainContainer["env"][0]["name"])
assert_equal(values[:env].values[0].to_s, mainContainer["env"][0]["value"])
assert_equal(values[:envTpl].keys[0].to_s, mainContainer["env"][1]["name"])
assert_equal(values[:env].keys[0].to_s, mainContainer["env"][1]["name"])
assert_equal("common-test-admin", mainContainer["env"][1]["value"])
end
it 'set "Dynamic/Tpl" environment variables' do
it 'set static "k/v pair style", templated "k/v pair style", static "k/explicitValueFrom pair style", and static "k/implicitValueFrom pair style" environment variables' do
values = {
envTpl: {
DYN_ENV: "{{ .Release.Name }}-admin"
env: {
DYN_ENV: "{{ .Release.Name }}-admin",
STATIC_ENV: 'value_of_env',
STATIC_EXPLICIT_ENV_FROM: {
valueFrom: {
fieldRef: {
fieldPath: "spec.nodeName"
}
}
},
STATIC_IMPLICIT_ENV_FROM: {
fieldRef: {
fieldPath: "spec.nodeName"
}
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
assert_equal(values[:envTpl].keys[0].to_s, mainContainer["env"][0]["name"])
assert_equal("common-test-admin", mainContainer["env"][0]["value"])
assert_equal(values[:env].keys[0].to_s, mainContainer["env"][1]["name"])
assert_equal("common-test-admin", mainContainer["env"][1]["value"])
assert_equal(values[:env].keys[1].to_s, mainContainer["env"][2]["name"])
assert_equal(values[:env].values[1].to_s, mainContainer["env"][2]["value"])
assert_equal(values[:env].keys[2].to_s, mainContainer["env"][3]["name"])
assert_equal(values[:env].values[2][:valueFrom][:fieldRef][:fieldPath], mainContainer["env"][3]["valueFrom"]["fieldRef"]["fieldPath"])
assert_equal(values[:env].keys[3].to_s, mainContainer["env"][4]["name"])
assert_equal(values[:env].values[3][:fieldRef][:fieldPath], mainContainer["env"][4]["valueFrom"]["fieldRef"]["fieldPath"])
end
it 'set "static" secret variables' do
@@ -211,170 +272,5 @@ class Test < ChartTest
end
end
describe 'container::persistence' do
it 'supports multiple volumeMounts' do
values = {
persistence: {
cache: {
enabled: true,
emptyDir: {
enabled: true
}
},
config: {
enabled: true,
existingClaim: "configClaim"
},
data: {
enabled: true,
existingClaim: "dataClaim"
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
# Check that all persistent volumes have mounts
values[:persistence].each { |key, value|
volumeMount = mainContainer["volumeMounts"].find{ |v| v["name"] == key.to_s }
refute_nil(volumeMount)
}
end
it 'defaults mountPath to persistence key' do
values = {
persistence: {
data: {
enabled: true,
existingClaim: "dataClaim"
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
volumeMount = mainContainer["volumeMounts"].find{ |v| v["name"] == "data" }
refute_nil(volumeMount)
assert_equal("/data", volumeMount["mountPath"])
end
it 'supports setting custom mountPath' do
values = {
persistence: {
data: {
enabled: true,
existingClaim: "dataClaim",
mountPath: "/myMountPath"
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
volumeMount = mainContainer["volumeMounts"].find{ |v| v["name"] == "data" }
refute_nil(volumeMount)
assert_equal("/myMountPath", volumeMount["mountPath"])
end
it 'supports setting subPath' do
values = {
persistence: {
data: {
enabled: true,
existingClaim: "dataClaim",
subPath: "mySubPath"
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
volumeMount = mainContainer["volumeMounts"].find{ |v| v["name"] == "data" }
refute_nil(volumeMount)
assert_equal("mySubPath", volumeMount["subPath"])
end
end
describe 'container::hostPathMounts' do
it 'supports multiple hostPathMounts' do
values = {
hostPathMounts: [
{
name: "data",
enabled: true,
mountPath: "/data",
hostPath: "/tmp"
},
{
name: "config",
enabled: true,
mountPath: "/config",
hostPath: "/tmp"
}
]
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
# Check that all hostPathMounts volumes have mounts
values[:hostPathMounts].each { |value|
volumeMount = mainContainer["volumeMounts"].find{ |v| v["name"] == "hostpathmounts-" + value[:name].to_s }
refute_nil(volumeMount)
}
end
it 'supports setting mountPath' do
values = {
hostPathMounts: [
{
name: "data",
enabled: true,
mountPath: "/data",
hostPath: "/tmp"
}
]
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
volumeMount = mainContainer["volumeMounts"].find{ |v| v["name"] == "hostpathmounts-data" }
refute_nil(volumeMount)
assert_equal("/data", volumeMount["mountPath"])
end
it 'supports setting subPath' do
values = {
hostPathMounts: [
{
name: "data",
enabled: true,
mountPath: "/data",
hostPath: "/tmp",
subPath: "mySubPath"
}
]
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
volumeMount = mainContainer["volumeMounts"].find{ |v| v["name"] == "hostpathmounts-data" }
refute_nil(volumeMount)
assert_equal("mySubPath", volumeMount["subPath"])
end
end
end
end
+13 -12
View File
@@ -13,14 +13,14 @@ class Test < ChartTest
end
it 'accepts "statefulset"' do
chart.value controllerType: 'statefulset'
chart.value controller: {type: 'statefulset'}
assert_nil(resource('Deployment'))
assert_nil(resource('DaemonSet'))
refute_nil(resource('StatefulSet'))
end
it 'accepts "daemonset"' do
chart.value controllerType: 'daemonset'
chart.value controller: {type: 'daemonset'}
assert_nil(resource('Deployment'))
assert_nil(resource('StatefulSet'))
refute_nil(resource('DaemonSet'))
@@ -29,31 +29,32 @@ class Test < ChartTest
describe 'controller::statefulset::volumeClaimTemplates' do
it 'volumeClaimTemplates should be empty by default' do
chart.value controllerType: 'statefulset'
chart.value controller: {type: 'statefulset'}
statefulset = chart.resources(kind: "StatefulSet").first
assert_nil(statefulset['spec']['volumeClaimTemplates'])
end
it 'can set values for volumeClaimTemplates' do
values = {
controllerType: 'statefulset',
volumeClaimTemplates: [
{
name: 'storage',
controller: {
type: 'statefulset',
},
volumeClaimTemplates: {
storage: {
accessMode: 'ReadWriteOnce',
size: '10Gi',
storageClass: 'storage'
}
]
}
}
chart.value values
statefulset = chart.resources(kind: "StatefulSet").first
volumeClaimTemplate = statefulset["spec"]["volumeClaimTemplates"].find{ |v| v["metadata"]["name"] == values[:volumeClaimTemplates][0][:name]}
volumeClaimTemplate = statefulset["spec"]["volumeClaimTemplates"].find{ |c| c["metadata"]["name"] == "storage"}
refute_nil(volumeClaimTemplate)
assert_equal(values[:volumeClaimTemplates][0][:accessMode], volumeClaimTemplate["spec"]["accessModes"][0])
assert_equal(values[:volumeClaimTemplates][0][:size], volumeClaimTemplate["spec"]["resources"]["requests"]["storage"])
assert_equal(values[:volumeClaimTemplates][0][:storageClass], volumeClaimTemplate["spec"]["storageClassName"])
assert_equal(values[:volumeClaimTemplates][:storage][:accessMode], volumeClaimTemplate["spec"]["accessModes"][0])
assert_equal(values[:volumeClaimTemplates][:storage][:size], volumeClaimTemplate["spec"]["resources"]["requests"]["storage"])
assert_equal(values[:volumeClaimTemplates][:storage][:storageClass], volumeClaimTemplate["spec"]["storageClassName"])
end
end
end
+101 -142
View File
@@ -6,37 +6,48 @@ class Test < ChartTest
describe @@chart.name do
describe 'ingress' do
baseValues = {
ingress: {
main: {
enabled: true
}
},
service: {
main: {
ports: {
http: {
port: 8080
}
}
}
}
}
it 'disabled when ingress.main.enabled: false' do
values = {
values = baseValues.deep_merge_override({
ingress: {
main: {
enabled: false
}
}
}
})
chart.value values
assert_nil(resource('Ingress'))
end
it 'enabled when ingress.main.enabled: true' do
values = {
ingress: {
main: {
enabled: true
}
}
}
values = baseValues
chart.value values
refute_nil(resource('Ingress'))
end
it 'tls can be provided' do
expectedPath = 'common-test.path'
values = {
values = baseValues.deep_merge_override({
ingress: {
main: {
enabled: true,
tls: [
{
hosts: [ 'hostname' ],
@@ -45,10 +56,10 @@ class Test < ChartTest
]
}
}
}
})
chart.value values
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test-main" }
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test" }
refute_nil(ingress)
assert_equal(values[:ingress][:main][:tls][0][:hosts][0], ingress["spec"]["tls"][0]["hosts"][0])
assert_equal(values[:ingress][:main][:tls][0][:secretName], ingress["spec"]["tls"][0]["secretName"])
@@ -56,10 +67,9 @@ class Test < ChartTest
it 'tls secret can be left empty' do
expectedPath = 'common-test.path'
values = {
values = baseValues.deep_merge_override({
ingress: {
main: {
enabled: true,
main:{
tls: [
{
hosts: [ 'hostname' ]
@@ -67,10 +77,10 @@ class Test < ChartTest
]
}
}
}
})
chart.value values
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test-main" }
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test" }
refute_nil(ingress)
assert_equal(values[:ingress][:main][:tls][0][:hosts][0], ingress["spec"]["tls"][0]["hosts"][0])
assert_equal(false, ingress["spec"]["tls"][0].key?("secretName"))
@@ -79,116 +89,125 @@ class Test < ChartTest
it 'tls secret template can be provided' do
expectedPath = 'common-test.path'
values = {
values = baseValues.deep_merge_override({
ingress: {
main: {
enabled: true,
tls: [
{
secretNameTpl: '{{ .Release.Name }}-secret'
secretName: '{{ .Release.Name }}-secret'
}
]
}
}
}
})
chart.value values
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test-main" }
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test" }
refute_nil(ingress)
assert_equal('common-test-secret', ingress["spec"]["tls"][0]["secretName"])
end
it 'path template can be provided' do
expectedPath = 'common-test.path'
values = {
values = baseValues.deep_merge_override({
ingress: {
main: {
enabled: true,
hosts: [
{
host: 'test.local',
paths: [
{
pathTpl: '{{ .Release.Name }}.path'
path: '{{ .Release.Name }}.path'
}
]
}
]
}
}
}
})
chart.value values
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test-main" }
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test" }
refute_nil(ingress)
assert_equal(expectedPath, ingress["spec"]["rules"][0]["http"]["paths"][0]["path"])
end
it 'hosts can be provided' do
values = {
values = baseValues.deep_merge_override({
ingress: {
main: {
enabled: true,
hosts: [
{
host: 'hostname'
host: 'hostname',
paths: [
{
path: "/"
}
]
}
]
}
}
}
})
chart.value values
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test-main" }
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test" }
refute_nil(ingress)
assert_equal(values[:ingress][:main][:hosts][0][:host], ingress["spec"]["rules"][0]["host"])
end
it 'hosts template can be provided' do
expectedHostName = 'common-test.hostname'
values = {
values = baseValues.deep_merge_override({
ingress: {
main: {
enabled: true,
hosts: [
{
hostTpl: '{{ .Release.Name }}.hostname'
}
]
}
}
}
chart.value values
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test-main" }
refute_nil(ingress)
assert_equal(expectedHostName, ingress["spec"]["rules"][0]["host"])
end
it 'custom service name / port can optionally be set on path level' do
values = {
ingress: {
main: {
enabled: true,
hosts: [
{
host: '{{ .Release.Name }}.hostname',
paths: [
{
path: '/'
},
{
path: '/second',
serviceName: 'pathService',
servicePort: 1234
path: "/"
}
]
}
]
}
}
}
})
chart.value values
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test-main" }
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test" }
refute_nil(ingress)
assert_equal(expectedHostName, ingress["spec"]["rules"][0]["host"])
end
it 'custom service name / port can optionally be set on path level' do
values = baseValues.deep_merge_override({
ingress: {
main: {
hosts: [
{
host: 'test.local',
paths: [
{
path: '/'
},
{
path: '/second',
service: {
name: 'pathService',
port: 1234
}
}
]
}
]
}
}
})
chart.value values
ingress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test" }
firstPath = ingress["spec"]["rules"][0]["http"]["paths"][0]
secondPath = ingress["spec"]["rules"][0]["http"]["paths"][1]
assert_equal("common-test", firstPath["backend"]["service"]["name"])
@@ -196,85 +215,25 @@ class Test < ChartTest
assert_equal("pathService", secondPath["backend"]["service"]["name"])
assert_equal(1234, secondPath["backend"]["service"]["port"]["number"])
end
end
describe 'additionalIngress' do
ingressValues = {
ingress: {
extra: {
it 'multiple ingress objects can be specified' do
values = baseValues.deep_merge_override({
ingress: {
main: {
enabled: true,
hosts: [
{
paths: [
{
path: '/'
}
]
}
]
primary: true
},
secondary: {
enabled: true
}
}
}
it 'can be specified' do
values = ingressValues
chart.value values
additionalIngress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test-extra" }
refute_nil(additionalIngress)
end
it 'refers to main Service by default' do
values = ingressValues
chart.value values
additionalIngress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test-extra" }
assert_equal("common-test", additionalIngress["spec"]["rules"][0]["http"]["paths"][0]["backend"]["service"]["name"])
assert_equal(8080, additionalIngress["spec"]["rules"][0]["http"]["paths"][0]["backend"]["service"]["port"]["number"])
end
it 'custom service name / port can be set on Ingress level' do
values = ingressValues.deep_merge_override({
ingress: {
extra: {
serviceName: "customService",
servicePort: 8081
}
}
})
chart.value values
additionalIngress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test-extra" }
assert_equal("customService", additionalIngress["spec"]["rules"][0]["http"]["paths"][0]["backend"]["service"]["name"])
assert_equal(8081, additionalIngress["spec"]["rules"][0]["http"]["paths"][0]["backend"]["service"]["port"]["number"])
end
it 'custom service name / port can optionally be set on path level' do
values = ingressValues.deep_merge_override({
ingress: {
extra: {
hosts: [
{
paths: [
{
path: '/'
},
{
path: '/second',
serviceName: 'pathService',
servicePort: 1234
}
]
}
]
}
}
})
chart.value values
additionalIngress = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test-extra" }
firstPath = additionalIngress["spec"]["rules"][0]["http"]["paths"][0]
secondPath = additionalIngress["spec"]["rules"][0]["http"]["paths"][1]
assert_equal("common-test", firstPath["backend"]["service"]["name"])
assert_equal(8080, firstPath["backend"]["service"]["port"]["number"])
assert_equal("pathService", secondPath["backend"]["service"]["name"])
assert_equal(1234, secondPath["backend"]["service"]["port"]["number"])
ingressMain = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test" }
ingressExtra = chart.resources(kind: "Ingress").find{ |s| s["metadata"]["name"] == "common-test-secondary" }
refute_nil(ingressMain)
refute_nil(ingressExtra)
end
end
end
+368
View File
@@ -0,0 +1,368 @@
# frozen_string_literal: true
require_relative '../../test_helper'
class Test < ChartTest
@@chart = Chart.new('charts/library/common-test')
describe @@chart.name do
describe 'pod::persistence' do
it 'multiple volumes' do
values = {
persistence: {
cache: {
enabled: true,
type: "emptyDir"
},
config: {
enabled: true,
existingClaim: "configClaim"
},
data: {
enabled: true,
existingClaim: "dataClaim"
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
volumes = deployment["spec"]["template"]["spec"]["volumes"]
volume = volumes.find{ |v| v["name"] == "cache"}
refute_nil(volume)
volume = volumes.find{ |v| v["name"] == "config"}
refute_nil(volume)
assert_equal('configClaim', volume["persistentVolumeClaim"]["claimName"])
volume = volumes.find{ |v| v["name"] == "data"}
refute_nil(volume)
assert_equal('dataClaim', volume["persistentVolumeClaim"]["claimName"])
end
it 'default nameSuffix' do
values = {
persistence: {
config: {
enabled: true
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
volumes = deployment["spec"]["template"]["spec"]["volumes"]
volume = volumes.find{ |v| v["name"] == "config"}
refute_nil(volume)
assert_equal('common-test-config', volume["persistentVolumeClaim"]["claimName"])
end
it 'custom nameSuffix' do
values = {
persistence: {
config: {
enabled: true,
nameOverride: "test"
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
volumes = deployment["spec"]["template"]["spec"]["volumes"]
volume = volumes.find{ |v| v["name"] == "config"}
refute_nil(volume)
assert_equal('common-test-test', volume["persistentVolumeClaim"]["claimName"])
end
it 'no nameSuffix' do
values = {
persistence: {
config: {
enabled: true,
nameOverride: "-"
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
volumes = deployment["spec"]["template"]["spec"]["volumes"]
volume = volumes.find{ |v| v["name"] == "config"}
refute_nil(volume)
assert_equal('common-test', volume["persistentVolumeClaim"]["claimName"])
end
end
describe 'pod::persistence::emptyDir' do
it 'can be configured' do
values = {
persistence: {
config: {
enabled: true,
type: "emptyDir"
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
volumes = deployment["spec"]["template"]["spec"]["volumes"]
volume = volumes.find{ |v| v["name"] == "config"}
refute_nil(volume)
assert_equal(Hash.new, volume["emptyDir"])
end
it 'medium can be configured' do
values = {
persistence: {
config: {
enabled: true,
type: "emptyDir",
medium: "memory"
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
volumes = deployment["spec"]["template"]["spec"]["volumes"]
volume = volumes.find{ |v| v["name"] == "config"}
refute_nil(volume)
assert_equal("memory", volume["emptyDir"]["medium"])
end
it 'sizeLimit can be configured' do
values = {
persistence: {
config: {
enabled: true,
type: "emptyDir",
medium: "memory",
sizeLimit: "1Gi"
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
volumes = deployment["spec"]["template"]["spec"]["volumes"]
volume = volumes.find{ |v| v["name"] == "config"}
refute_nil(volume)
assert_equal("1Gi", volume["emptyDir"]["sizeLimit"])
end
end
describe 'pod::persistenceList' do
it 'multiple volumes' do
values = {
persistenceList: [
{
name: "data",
enabled: true,
type: "hostPath",
mountPath: "/data",
hostPath: "/tmp1"
},
{
name: "configlist",
type: "hostPath",
enabled: true,
mountPath: "/config",
hostPath: "/tmp2"
}
]
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
volumes = deployment["spec"]["template"]["spec"]["volumes"]
volume = volumes.find{ |v| v["name"] == "data"}
refute_nil(volume)
assert_equal('/tmp1', volume["hostPath"]["path"])
volume = volumes.find{ |v| v["name"] == "configlist"}
refute_nil(volume)
assert_equal('/tmp2', volume["hostPath"]["path"])
end
it 'emptyDir can be enabled' do
values = {
persistenceList: [
{
name: "data",
type: "emptyDir",
enabled: true,
mountPath: "/data"
}
]
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
volumes = deployment["spec"]["template"]["spec"]["volumes"]
volume = volumes.find{ |v| v["name"] == "data"}
refute_nil(volume)
assert_equal(Hash.new, volume["emptyDir"])
end
end
describe 'container::persistence' do
it 'supports multiple volumeMounts' do
values = {
persistence: {
cache: {
enabled: true,
type: "emptyDir"
},
config: {
enabled: true,
existingClaim: "configClaim"
},
data: {
enabled: true,
existingClaim: "dataClaim"
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
# Check that all persistent volumes have mounts
values[:persistence].each { |key, value|
volumeMount = mainContainer["volumeMounts"].find{ |v| v["name"] == key.to_s }
refute_nil(volumeMount)
}
end
it 'defaults mountPath to persistence key' do
values = {
persistence: {
data: {
enabled: true,
existingClaim: "dataClaim"
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
volumeMount = mainContainer["volumeMounts"].find{ |v| v["name"] == "data" }
refute_nil(volumeMount)
assert_equal("/data", volumeMount["mountPath"])
end
it 'supports setting custom mountPath' do
values = {
persistence: {
data: {
enabled: true,
existingClaim: "dataClaim",
mountPath: "/myMountPath"
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
volumeMount = mainContainer["volumeMounts"].find{ |v| v["name"] == "data" }
refute_nil(volumeMount)
assert_equal("/myMountPath", volumeMount["mountPath"])
end
it 'supports setting subPath' do
values = {
persistence: {
data: {
enabled: true,
existingClaim: "dataClaim",
subPath: "mySubPath"
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
volumeMount = mainContainer["volumeMounts"].find{ |v| v["name"] == "data" }
refute_nil(volumeMount)
assert_equal("mySubPath", volumeMount["subPath"])
end
end
describe 'container::persistenceList' do
it 'supports multiple persistenceList' do
values = {
persistenceList: [
{
name: "data",
enabled: true,
mountPath: "/data",
hostPath: "/tmp"
},
{
name: "config",
enabled: true,
mountPath: "/config",
hostPath: "/tmp"
}
]
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
# Check that all persistenceList volumes have mounts
values[:persistenceList].each { |value|
volumeMount = mainContainer["volumeMounts"].find{ |v| v["name"] == value[:name].to_s }
refute_nil(volumeMount)
}
end
it 'supports setting mountPath' do
values = {
persistenceList: [
{
name: "data",
enabled: true,
mountPath: "/data",
hostPath: "/tmp"
}
]
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
volumeMount = mainContainer["volumeMounts"].find{ |v| v["name"] == "data" }
refute_nil(volumeMount)
assert_equal("/data", volumeMount["mountPath"])
end
it 'supports setting subPath' do
values = {
persistenceList: [
{
name: "data",
enabled: true,
mountPath: "/data",
hostPath: "/tmp",
subPath: "mySubPath"
}
]
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
volumeMount = mainContainer["volumeMounts"].find{ |v| v["name"] == "data" }
refute_nil(volumeMount)
assert_equal("mySubPath", volumeMount["subPath"])
end
end
end
end
+6 -213
View File
@@ -12,7 +12,12 @@ class Test < ChartTest
end
it 'accepts integer as value' do
chart.value replicas: 3
values = {
controller: {
replicas: 3
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
assert_equal(3, deployment["spec"]["replicas"])
end
@@ -100,217 +105,5 @@ class Test < ChartTest
refute_nil(additionalContainer)
end
end
describe 'pod::persistence' do
it 'multiple volumes' do
values = {
persistence: {
cache: {
enabled: true,
emptyDir: {
enabled: true
}
},
config: {
enabled: true,
existingClaim: "configClaim",
emptyDir: {
enabled: false
}
},
data: {
enabled: true,
existingClaim: "dataClaim"
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
volumes = deployment["spec"]["template"]["spec"]["volumes"]
volume = volumes.find{ |v| v["name"] == "cache"}
refute_nil(volume)
volume = volumes.find{ |v| v["name"] == "config"}
refute_nil(volume)
assert_equal('configClaim', volume["persistentVolumeClaim"]["claimName"])
volume = volumes.find{ |v| v["name"] == "data"}
refute_nil(volume)
assert_equal('dataClaim', volume["persistentVolumeClaim"]["claimName"])
end
it 'default nameSuffix' do
values = {
persistence: {
config: {
enabled: true,
emptyDir: {
enabled: false
}
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
volumes = deployment["spec"]["template"]["spec"]["volumes"]
volume = volumes.find{ |v| v["name"] == "config"}
refute_nil(volume)
assert_equal('common-test-config', volume["persistentVolumeClaim"]["claimName"])
end
it 'custom nameSuffix' do
values = {
persistence: {
config: {
enabled: true,
nameSuffix: "test",
emptyDir: {
enabled: false
}
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
volumes = deployment["spec"]["template"]["spec"]["volumes"]
volume = volumes.find{ |v| v["name"] == "config"}
refute_nil(volume)
assert_equal('common-test-test', volume["persistentVolumeClaim"]["claimName"])
end
it 'no nameSuffix' do
values = {
persistence: {
config: {
enabled: true,
nameSuffix: "-",
emptyDir: {
enabled: false
}
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
volumes = deployment["spec"]["template"]["spec"]["volumes"]
volume = volumes.find{ |v| v["name"] == "config"}
refute_nil(volume)
assert_equal('common-test', volume["persistentVolumeClaim"]["claimName"])
end
end
describe 'pod::persistence::emptyDir' do
it 'can be configured' do
values = {
persistence: {
config: {
enabled: true,
emptyDir: {
enabled: true
}
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
volumes = deployment["spec"]["template"]["spec"]["volumes"]
volume = volumes.find{ |v| v["name"] == "config"}
refute_nil(volume)
assert_equal(Hash.new, volume["emptyDir"])
end
it 'medium can be configured' do
values = {
persistence: {
config: {
enabled: true,
emptyDir: {
enabled: true,
medium: "memory"
}
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
volumes = deployment["spec"]["template"]["spec"]["volumes"]
volume = volumes.find{ |v| v["name"] == "config"}
refute_nil(volume)
assert_equal("memory", volume["emptyDir"]["medium"])
end
it 'sizeLimit can be configured' do
values = {
persistence: {
config: {
enabled: true,
emptyDir: {
enabled: true,
medium: "memory",
sizeLimit: "1Gi"
}
}
}
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
volumes = deployment["spec"]["template"]["spec"]["volumes"]
volume = volumes.find{ |v| v["name"] == "config"}
refute_nil(volume)
assert_equal("1Gi", volume["emptyDir"]["sizeLimit"])
end
end
describe 'pod::hostPathMounts' do
it 'multiple volumes' do
values = {
hostPathMounts: [
{
name: "data",
enabled: true,
mountPath: "/data",
hostPath: "/tmp1"
},
{
name: "config",
enabled: true,
mountPath: "/config",
hostPath: "/tmp2"
}
]
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
volumes = deployment["spec"]["template"]["spec"]["volumes"]
volume = volumes.find{ |v| v["name"] == "hostpathmounts-data"}
refute_nil(volume)
assert_equal('/tmp1', volume["hostPath"]["path"])
volume = volumes.find{ |v| v["name"] == "hostpathmounts-config"}
refute_nil(volume)
assert_equal('/tmp2', volume["hostPath"]["path"])
end
it 'emptyDir can be enabled' do
values = {
hostPathMounts: [
{
name: "data",
enabled: true,
emptyDir: true,
mountPath: "/data"
}
]
}
chart.value values
deployment = chart.resources(kind: "Deployment").first
volumes = deployment["spec"]["template"]["spec"]["volumes"]
volume = volumes.find{ |v| v["name"] == "hostpathmounts-data"}
refute_nil(volume)
assert_equal(Hash.new, volume["emptyDir"])
end
end
end
end
+44 -46
View File
@@ -5,13 +5,13 @@ class Test < ChartTest
@@chart = Chart.new('charts/library/common-test')
describe @@chart.name do
describe 'configmap::portal-defaults' do
describe 'portal::configmap::defaults' do
it 'no configmap exists by default' do
configmap = chart.resources(kind: "ConfigMap").first
assert_nil(configmap)
end
it 'creates configmap whe enabled' do
it 'creates configmap when enabled' do
values = {
portal: {
enabled: true
@@ -65,7 +65,7 @@ class Test < ChartTest
assert_equal("443", configmap["data"]["port"])
end
it 'uses protocol "https" by default' do
it 'uses protocol "http" by default' do
values = {
portal: {
enabled: true
@@ -78,7 +78,7 @@ class Test < ChartTest
}
chart.value values
configmap = chart.resources(kind: "ConfigMap").first
assert_equal("https", configmap["data"]["protocol"])
assert_equal("http", configmap["data"]["protocol"])
end
it 'uses path "/" by default' do
@@ -98,7 +98,7 @@ class Test < ChartTest
end
end
describe 'configmap::portal-overrides' do
describe 'portal::configmap::overrides' do
it 'ingressPort can be overridden' do
values = {
portal: {
@@ -151,7 +151,7 @@ class Test < ChartTest
end
end
describe 'configmap::portal-nodePort' do
describe 'portal::configmap::nodeport' do
it 'nodePort host defaults to "$node_ip"' do
values = {
portal: {
@@ -162,14 +162,16 @@ class Test < ChartTest
enabled: false
}
},
services: {
service: {
main: {
type: "NodePort",
port: {
nodePort: 666
type: "NodePort",
ports: {
main: {
nodePort: 666
}
}
}
}
}
}
chart.value values
configmap = chart.resources(kind: "ConfigMap").first
@@ -181,18 +183,17 @@ class Test < ChartTest
portal: {
enabled: true
},
ingress: {
service: {
main: {
enabled: false
type: "NodePort",
ports: {
main: {
enabled: true,
port: 8080,
nodePort: 666
}
}
}
},
services: {
main: {
type: "NodePort",
port: {
nodePort: 666
}
}
}
}
chart.value values
@@ -205,24 +206,23 @@ class Test < ChartTest
portal: {
enabled: true
},
ingress: {
service: {
main: {
enabled: false
type: "NodePort",
ports: {
main: {
enabled: true,
port: 8080,
nodePort: 666,
protocol: "HTTPS"
}
}
}
},
services: {
main: {
type: "NodePort",
port: {
nodePort: 666,
protocol: "HTTPS"
}
}
}
}
chart.value values
configmap = chart.resources(kind: "ConfigMap").first
assert_equal(values[:services][:main][:port][:protocol], configmap["data"]["protocol"])
assert_equal("https", configmap["data"]["protocol"])
end
it 'uses nodeport port protocol as protocol (HTTP)' do
@@ -230,28 +230,26 @@ class Test < ChartTest
portal: {
enabled: true
},
ingress: {
service: {
main: {
enabled: false
type: "NodePort",
ports: {
main: {
enabled: true,
nodePort: 666,
protocol: "HTTP"
}
}
}
},
services: {
main: {
type: "NodePort",
port: {
nodePort: 666,
protocol: "HTTP"
}
}
}
}
chart.value values
configmap = chart.resources(kind: "ConfigMap").first
assert_equal(values[:services][:main][:port][:protocol], configmap["data"]["protocol"])
assert_equal("http", configmap["data"]["protocol"])
end
end
describe 'configmap::portal-Ingress' do
describe 'portal::configmap::ingress' do
it 'uses ingress host' do
values = {
portal: {
+2 -16
View File
@@ -24,7 +24,7 @@ class Test < ChartTest
persistence: {
config: {
enabled: true,
nameSuffix: 'customSuffix'
nameOverride: 'customSuffix'
}
}
}
@@ -33,26 +33,12 @@ class Test < ChartTest
refute_nil(pvc)
end
it 'name can be overridden by nameOverride' do
values = {
persistence: {
config: {
enabled: true,
nameOverride: 'customname'
}
}
}
chart.value values
pvc = chart.resources(kind: "PersistentVolumeClaim").find{ |s| s["metadata"]["name"] == "customname" }
refute_nil(pvc)
end
it 'nameSuffix can be skipped' do
values = {
persistence: {
config: {
enabled: true,
nameSuffix: '-'
nameOverride: '-'
}
}
}
+151 -84
View File
@@ -6,10 +6,25 @@ class Test < ChartTest
describe @@chart.name do
describe 'service::ports settings' do
baseValues = {
service: {
main: {
ports: {
main: {
port: 8080
}
}
}
}
}
default_name = 'main'
default_port = 8080
it 'defaults to name "servicename" on port 8080' do
it 'defaults to name "http" on port 8080' do
values = baseValues
chart.value values
service = chart.resources(kind: "Service").find{ |s| s["metadata"]["name"] == "common-test" }
refute_nil(service)
assert_equal(default_port, service["spec"]["ports"].first["port"])
@@ -23,72 +38,102 @@ class Test < ChartTest
assert_equal(default_name, mainContainer["ports"].first["name"])
end
it 'port name can be overridden' do
values = {
services: {
it 'port name can be set' do
values = baseValues.deep_merge_override({
service: {
main: {
port: {
name: "server",
},
},
},
}
ports: {
main: {
enabled: false
},
server: {
enabled: true,
port: 8080
}
}
}
}
})
chart.value values
service = chart.resources(kind: "Service").find{ |s| s["metadata"]["name"] == "common-test" }
refute_nil(service)
assert_equal(default_port, service["spec"]["ports"].first["port"])
assert_equal(values[:services][:main][:port][:name], service["spec"]["ports"].first["targetPort"])
assert_equal(values[:services][:main][:port][:name], service["spec"]["ports"].first["name"])
assert_equal('server', service["spec"]["ports"].first["targetPort"])
assert_equal('server', service["spec"]["ports"].first["name"])
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
assert_equal(default_port, mainContainer["ports"].first["containerPort"])
assert_equal(values[:services][:main][:port][:name], mainContainer["ports"].first["name"])
assert_equal('server', mainContainer["ports"].first["name"])
end
it 'name suffix can be overridden' do
values = baseValues.deep_merge_override({
service: {
main: {
nameOverride: 'http'
}
}
})
chart.value values
service = chart.resources(kind: "Service").find{ |s| s["metadata"]["name"] == "common-test-#{values[:service][:main][:nameOverride]}" }
refute_nil(service)
end
it 'targetPort can be overridden' do
values = {
services: {
values = baseValues.deep_merge_override({
service: {
main: {
port: {
targetPort: 80,
},
},
},
}
ports: {
main: {
targetPort: 80
}
}
}
}
})
chart.value values
service = chart.resources(kind: "Service").find{ |s| s["metadata"]["name"] == "common-test" }
refute_nil(service)
assert_equal(default_port, service["spec"]["ports"].first["port"])
assert_equal(values[:services][:main][:port][:targetPort], service["spec"]["ports"].first["targetPort"])
assert_equal(80, service["spec"]["ports"].first["targetPort"])
assert_equal(default_name, service["spec"]["ports"].first["name"])
deployment = chart.resources(kind: "Deployment").first
containers = deployment["spec"]["template"]["spec"]["containers"]
mainContainer = containers.find{ |c| c["name"] == "common-test" }
assert_equal(values[:services][:main][:port][:targetPort], mainContainer["ports"].first["containerPort"])
assert_equal(80, mainContainer["ports"].first["containerPort"])
assert_equal(default_name, mainContainer["ports"].first["name"])
end
it 'targetPort cannot be a named port' do
values = {
services: {
values = baseValues.deep_merge_override({
service: {
main: {
port: {
targetPort: "test",
},
},
},
}
ports: {
main: {
targetPort: 'test'
}
}
}
}
})
chart.value values
exception = assert_raises HelmCompileError do
chart.execute_helm_template!
end
assert_match("Our charts do not support named ports for targetPort. (port name #{default_name}, targetPort #{values[:services][:main][:port][:targetPort]})", exception.message)
assert_match("Our charts do not support named ports for targetPort. (port name #{default_name}, targetPort test)", exception.message)
end
it 'protocol defaults to TCP' do
values = baseValues
chart.value values
service = chart.resources(kind: "Service").find{ |s| s["metadata"]["name"] == "common-test" }
refute_nil(service)
assert_equal("TCP", service["spec"]["ports"].first["protocol"])
@@ -100,16 +145,19 @@ class Test < ChartTest
end
it 'protocol is TCP when set to TCP explicitly' do
values = {
services: {
values = baseValues.deep_merge_override({
service: {
main: {
port: {
protocol: "TCP",
},
},
},
}
ports: {
main: {
protocol: 'TCP'
}
}
}
}
})
chart.value values
service = chart.resources(kind: "Service").find{ |s| s["metadata"]["name"] == "common-test" }
refute_nil(service)
assert_equal("TCP", service["spec"]["ports"].first["protocol"])
@@ -121,16 +169,19 @@ class Test < ChartTest
end
it 'protocol is TCP when set to HTTP explicitly' do
values = {
services: {
values = baseValues.deep_merge_override({
service: {
main: {
port: {
protocol: "HTTP",
},
},
},
}
ports: {
main: {
protocol: 'HTTP'
}
}
}
}
})
chart.value values
service = chart.resources(kind: "Service").find{ |s| s["metadata"]["name"] == "common-test" }
refute_nil(service)
assert_equal("TCP", service["spec"]["ports"].first["protocol"])
@@ -142,16 +193,19 @@ class Test < ChartTest
end
it 'protocol is TCP when set to HTTPS explicitly' do
values = {
services: {
values = baseValues.deep_merge_override({
service: {
main: {
port: {
protocol: "HTTPS",
},
},
},
}
ports: {
main: {
protocol: 'HTTPS'
}
}
}
}
})
chart.value values
service = chart.resources(kind: "Service").find{ |s| s["metadata"]["name"] == "common-test" }
refute_nil(service)
assert_equal("TCP", service["spec"]["ports"].first["protocol"])
@@ -163,16 +217,19 @@ class Test < ChartTest
end
it 'protocol is UDP when set to UDP explicitly' do
values = {
services: {
values = baseValues.deep_merge_override({
service: {
main: {
port: {
protocol: "UDP",
},
},
},
}
ports: {
main: {
protocol: 'UDP'
}
}
}
}
})
chart.value values
service = chart.resources(kind: "Service").find{ |s| s["metadata"]["name"] == "common-test" }
refute_nil(service)
assert_equal("UDP", service["spec"]["ports"].first["protocol"])
@@ -184,35 +241,45 @@ class Test < ChartTest
end
it 'No annotations get set by default' do
service = chart.resources(kind: "Service").find{ |s| s["metadata"]["name"] == "common-test" }
refute_nil(service)
assert_nil(service["metadata"]["annotations"])
end
it 'TCP port protocol does not set annotations' do
values = {
services: {
main: {
port: {
protocol: 'TCP'
}
}
}
}
values = baseValues
chart.value values
service = chart.resources(kind: "Service").find{ |s| s["metadata"]["name"] == "common-test" }
refute_nil(service)
assert_nil(service["metadata"]["annotations"])
end
it 'HTTPS port protocol sets traefik HTTPS annotation' do
values = {
services: {
it 'TCP port protocol does not set annotations' do
values = baseValues.deep_merge_override({
service: {
main: {
port: {
protocol: 'HTTPS'
ports: {
main: {
protocol: 'TCP'
}
}
}
}
}
})
chart.value values
service = chart.resources(kind: "Service").find{ |s| s["metadata"]["name"] == "common-test" }
refute_nil(service)
assert_nil(service["metadata"]["annotations"])
end
it 'HTTPS port protocol sets traefik HTTPS annotation' do
values = baseValues.deep_merge_override({
service: {
main: {
ports: {
main: {
protocol: 'HTTPS'
}
}
}
}
})
chart.value values
service = chart.resources(kind: "Service").find{ |s| s["metadata"]["name"] == "common-test" }
refute_nil(service)