Skip to content

Commit

Permalink
TIKA-4232 Create and execute unit tests for tika-helm (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
lewismc authored May 10, 2024
1 parent 90c4ef7 commit a713d53
Show file tree
Hide file tree
Showing 13 changed files with 314 additions and 8 deletions.
30 changes: 29 additions & 1 deletion .github/workflows/lint-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,39 @@ jobs:
if [[ -n "$changed" ]]; then
echo "::set-output name=changed::true"
fi
shell: bash
- name: Run chart-testing (lint)
run: ct lint --target-branch ${{ github.event.repository.default_branch }} --charts .
shell: bash
- name: Create kind cluster
uses: helm/[email protected]
if: steps.list-changed.outputs.changed == 'true'
- name: Uninstall helm-unittest if present
run: |
helm plugin uninstall unittest >/dev/null 2>/dev/null \
|| echo "Failed to uninstall plugin, assuming it's not present."
shell: bash
- name: Install latest helm-unittest
run: |
echo "Installing latest version of helm-unittest"
helm plugin install https://github.com/helm-unittest/helm-unittest >/dev/null 2>/dev/null
shell: bash
- name: Assemble list of chart directories to test
run: |
tr ' ' '\n' <<< . | grep -v '^$' > charts-to-test || true
find . -type f -name 'Chart.yaml' -exec dirname {} \; > all-charts
[ -z . ] && mv all-charts charts-to-test || true
shell: bash
- name: Fetch chart dependencies
run: |
for chart in $(cat charts-to-test); do
helm dependency update "$chart" >/dev/null
done
shell: bash
- name: Run unit tests
run: helm unittest --color $(cat charts-to-test)
shell: bash
- name: Run chart-testing (install)
if: steps.list-changed.outputs.changed == 'true'
run: ct install --target-branch ${{ github.event.repository.default_branch }} --charts .
if: steps.list-changed.outputs.changed == 'true'
shell: bash
2 changes: 2 additions & 0 deletions .github/workflows/pluto.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ jobs:
wget https://github.com/FairwindsOps/pluto/releases/download/v${{ env.PLUTO_VERSION }}/pluto_${{ env.PLUTO_VERSION }}_linux_amd64.tar.gz -O - | tar -xz
mv pluto /usr/local/bin/pluto
chmod +x /usr/local/bin/pluto
shell: bash
- name: Set up Helm
uses: azure/[email protected]
- name: verify helm chart
run: |
helm template . | pluto detect -omarkdown - >> $GITHUB_STEP_SUMMARY
shell: bash
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test-output.xml
1 change: 1 addition & 0 deletions .helmignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
.idea/
*.tmproj
.vscode/
tests
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ will work with the version of Tika you are installing.
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->


- [tika-helm](#tika-helm)
- [Requirements](#requirements)
- [Installing](#installing)
Expand All @@ -40,7 +39,6 @@ will work with the version of Tika you are installing.
<!-- Use this to update TOC: -->
<!-- docker run --rm -it -v $(pwd):/usr/src jorgeandrada/doctoc --github -->


## Requirements

* Kubernetes >= 1.14
Expand Down Expand Up @@ -114,11 +112,14 @@ Please check `artifacthub.io/changes` in `Chart.yaml` before upgrading.
| --------- | ----------- | ------- |
| `...` | ... | ... |

### Deprecated
## Testing

| Parameter | Description | Default |
| --------- | ----------- | ------- |
| `...` | ... | `...` |
```
helm plugin install https://github.com/helm-unittest/helm-unittest.git
helm unittest .
```

See [helm-unittest][] for canonical documentation.

## Contributing

Expand Down Expand Up @@ -148,6 +149,7 @@ The code is licensed permissively under the [Apache License v2.0][].
[CHANGELOG.md]: https://github.com/apache/tika-helm/blob/master/CHANGELOG.md
[CONTRIBUTING]: https://github.com/apache/tika#contributing-via-github
[apache/tika]: https://github.com/apache/tika-docker
[helm-unittest]: https://github.com/helm-unittest/helm-unittest
[Helm chart]: https://helm.sh/docs/topics/charts/
[Kubernetes]: https://kubernetes.io/
[Tika Docker image]: https://hub.docker.com/r/apache/tika/tags?page=1&ordering=last_updated
Expand Down
18 changes: 18 additions & 0 deletions templates/networkpolicy.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://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.

---
{{- if .Values.networkPolicy.enabled }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
Expand Down
62 changes: 62 additions & 0 deletions tests/deployment_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://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.

suite: test deployment
templates:
- deployment.yaml
tests:
- it: should pass
set:
image.tag: latest
asserts:
- isKind:
of: Deployment
- isAPIVersion:
of: apps/v1
- matchRegex:
path: metadata.name
pattern: RELEASE-NAME-tika
- equal:
path: spec.template.spec.containers[0].image
value: apache/tika:latest
- lengthEqual:
path: spec.template.spec.containers
count: 1
- isSubset:
path: spec.template.spec.containers[0]
content:
livenessProbe:
httpGet:
path: /
port: 9998
scheme: HTTP
initialDelaySeconds: 15
timeoutSeconds: 30
failureThreshold: 20
periodSeconds: 5
- isSubset:
path: spec.template.spec.containers[0]
content:
readinessProbe:
httpGet:
path: /
port: 9998
scheme: HTTP
initialDelaySeconds: 15
timeoutSeconds: 30
failureThreshold: 20
periodSeconds: 5
41 changes: 41 additions & 0 deletions tests/hpa_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://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.

suite: test hpa
templates:
- hpa.yaml
tests:
- it: should pass
set:
autoscaling.enabled: true
asserts:
- isKind:
of: HorizontalPodAutoscaler
- isAPIVersion:
of: autoscaling/v2
- matchRegex:
path: metadata.name
pattern: RELEASE-NAME-tika
- equal:
path: spec.minReplicas
value: 1
- equal:
path: spec.maxReplicas
value: 100
- lengthEqual:
path: spec.metrics
count: 2
40 changes: 40 additions & 0 deletions tests/ingress_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://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.

suite: test ingress
templates:
- ingress.yaml
tests:
- it: should pass
set:
image.tag: latest
ingress.enabled: true
Capabilities.KubeVersion.GitVersion: 1.20
ingress.tls:
- secretName: chart-example-tls
hosts:
- chart-example.local
asserts:
- containsDocument:
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata.name: RELEASE-NAME-tika
- isNotNullOrEmpty:
path: spec.tls
- lengthEqual:
path: spec.rules
count: 1
38 changes: 38 additions & 0 deletions tests/networkpolicy_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://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.

suite: test networkpolicy
templates:
- networkpolicy.yaml
tests:
- it: should pass
set:
image.tag: latest
networkPolicy.enabled: true
networkPolicy.allowExternal: false
asserts:
- isKind:
of: NetworkPolicy
- matchRegex:
path: metadata.name
pattern: RELEASE-NAME-tika
- isAPIVersion:
of: networking.k8s.io/v1
- isNullOrEmpty:
path: spec.egress[0]
- isNotNullOrEmpty:
path: spec.ingress[0].from
41 changes: 41 additions & 0 deletions tests/service_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://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.

suite: test service
templates:
- service.yaml
tests:
- it: should pass
set:
image.tag: latest
asserts:
- isKind:
of: Service
- matchRegex:
path: metadata.name
pattern: RELEASE-NAME-tika
- isAPIVersion:
of: v1
- equal:
path: spec.type
value: ClusterIP
- lengthEqual:
path: spec.ports
count: 1
- equal:
path: spec.ports[0].port
value: 9998
32 changes: 32 additions & 0 deletions tests/serviceaccount_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://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.

suite: test serviceaccount
templates:
- serviceaccount.yaml
tests:
- it: should pass
set:
image.tag: latest
asserts:
- isKind:
of: ServiceAccount
- isAPIVersion:
of: v1
- matchRegex:
path: metadata.name
pattern: RELEASE-NAME-tika
2 changes: 1 addition & 1 deletion values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ resources:
memory: 1500Mi

autoscaling:
apiVersion: autoscaling/v2beta1
apiVersion: autoscaling/v2
enabled: false
minReplicas: 1
maxReplicas: 100
Expand Down

0 comments on commit a713d53

Please sign in to comment.