Skip to content

Commit

Permalink
feat(test): add Helm unittests for default values
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoscode committed Jun 27, 2023
1 parent 264f1d4 commit c0f26e4
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ tasks:
desc: Executes helm unittests
dir: charts/managed-identity-wallet
cmds:
- helm unittest -f tests/**/*_test.yaml .
- helm unittest .

build-app:
desc: Build the whole app
Expand Down
97 changes: 97 additions & 0 deletions charts/managed-identity-wallet/tests/default_deployment_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# /********************************************************************************
# * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
# *
# * See the NOTICE file(s) distributed with this work for additional
# * information regarding copyright ownership.
# *
# * This program and the accompanying materials are made available under the
# * terms of the Apache License, Version 2.0 which is available at
# * https://www.apache.org/licenses/LICENSE-2.0.
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# * License for the specific language governing permissions and limitations
# * under the License.
# *
# * SPDX-License-Identifier: Apache-2.0
# ********************************************************************************/

suite: test default deployment
chart:
version: 9.9.9+test
appVersion: 9.9.9
tests:
- it: should have correct metadata
template: templates/deployment.yaml
asserts:
- hasDocuments:
count: 1
- containsDocument:
kind: Deployment
apiVersion: apps/v1
name: RELEASE-NAME-managed-identity-wallet
- isSubset:
path: metadata.labels
content:
helm.sh/chart: managed-identity-wallet-9.9.9_test
app.kubernetes.io/name: managed-identity-wallet
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/version: "9.9.9"
app.kubernetes.io/managed-by: Helm

- it: must have important values set
template: templates/deployment.yaml
asserts:
- equal:
path: spec.replicas
value: 1
- lengthEqual:
path: spec.template.spec.containers
count: 1
- isNotEmpty:
path: spec.template.spec.serviceAccountName
- contains:
path: spec.template.spec.containers[0].ports
content:
name: http
containerPort: 8080
protocol: TCP

- it: must have probes set
template: templates/deployment.yaml
asserts:
- isNotEmpty:
path: spec.template.spec.containers[0].livenessProbe
- isNotEmpty:
path: spec.template.spec.containers[0].readinessProbe

- it: must have resource limits set
template: templates/deployment.yaml
asserts:
- isNotEmpty:
path: spec.template.spec.containers[0].resources
- isNotEmpty:
path: spec.template.spec.containers[0].resources.limits
- isNotEmpty:
path: spec.template.spec.containers[0].resources.limits.cpu
- isNotEmpty:
path: spec.template.spec.containers[0].resources.limits.memory
- isNotEmpty:
path: spec.template.spec.containers[0].resources.requests
- isNotEmpty:
path: spec.template.spec.containers[0].resources.requests.cpu
- isNotEmpty:
path: spec.template.spec.containers[0].resources.requests.memory

- it: must have a security context
template: templates/deployment.yaml
asserts:
- isSubset:
path: spec.template.spec.containers[0].securityContext
content:
allowPrivilegeEscalation: false
privileged: false
runAsGroup: 11111
runAsNonRoot: true
runAsUser: 11111
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# /********************************************************************************
# * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
# *
# * See the NOTICE file(s) distributed with this work for additional
# * information regarding copyright ownership.
# *
# * This program and the accompanying materials are made available under the
# * terms of the Apache License, Version 2.0 which is available at
# * https://www.apache.org/licenses/LICENSE-2.0.
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# * License for the specific language governing permissions and limitations
# * under the License.
# *
# * SPDX-License-Identifier: Apache-2.0
# ********************************************************************************/

suite: test default serviceaccount
chart:
version: 9.9.9+test
appVersion: 9.9.9
tests:
- it: should have correct metadata
template: templates/serviceaccount.yaml
asserts:
- hasDocuments:
count: 1
- containsDocument:
kind: ServiceAccount
apiVersion: v1
name: RELEASE-NAME-managed-identity-wallet
- isSubset:
path: metadata.labels
content:
helm.sh/chart: managed-identity-wallet-9.9.9_test
app.kubernetes.io/name: managed-identity-wallet
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/version: "9.9.9"
app.kubernetes.io/managed-by: Helm
59 changes: 59 additions & 0 deletions charts/managed-identity-wallet/tests/default_service_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# /********************************************************************************
# * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
# *
# * See the NOTICE file(s) distributed with this work for additional
# * information regarding copyright ownership.
# *
# * This program and the accompanying materials are made available under the
# * terms of the Apache License, Version 2.0 which is available at
# * https://www.apache.org/licenses/LICENSE-2.0.
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# * License for the specific language governing permissions and limitations
# * under the License.
# *
# * SPDX-License-Identifier: Apache-2.0
# ********************************************************************************/

suite: test default service
chart:
version: 9.9.9+test
appVersion: 9.9.9
tests:
- it: should have correct metadata
template: templates/service.yaml
asserts:
- hasDocuments:
count: 1
- containsDocument:
kind: Service
apiVersion: v1
name: RELEASE-NAME-managed-identity-wallet
- isSubset:
path: metadata.labels
content:
helm.sh/chart: managed-identity-wallet-9.9.9_test
app.kubernetes.io/name: managed-identity-wallet
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/version: "9.9.9"
app.kubernetes.io/managed-by: Helm

- it: must have type set to ClusterIP
template: templates/service.yaml
asserts:
- equal:
path: spec.type
value: ClusterIP

- it: must have ports set
template: templates/service.yaml
asserts:
- contains:
path: spec.ports
content:
name: http
targetPort: http
port: 8080
protocol: TCP
14 changes: 0 additions & 14 deletions charts/managed-identity-wallet/tests/deployment_default_test.yaml

This file was deleted.

0 comments on commit c0f26e4

Please sign in to comment.