Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Runs when this chart tree is the root of the GitHub repository (e.g. fluid-pub/chart-workload).

name: Helm chart CI

on:
Expand All @@ -23,3 +21,17 @@ jobs:

- name: Helm lint
run: helm lint .

unittest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5

- name: Install Helm
uses: azure/setup-helm@v5

- name: Install helm-unittest plugin
run: helm plugin install https://github.com/helm-unittest/helm-unittest --version v0.6.3 --verify=false

- name: Helm unittest
run: helm unittest .
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,12 @@ extraEnvFrom:
- `image.repository` / `image.tag` — workload image (GHCR).
- `credentialsSecret` — optional file-based credentials mount.
- `service.enabled` — only if the workload exposes HTTP.

## Chart tests

```bash
helm plugin install https://github.com/helm-unittest/helm-unittest --version v0.6.3 --verify=false
helm unittest .
```

See [`tests/README.md`](tests/README.md). CI runs `helm lint` and `helm unittest .` on pull requests.
31 changes: 31 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Helm chart unit tests (`fluid-workload`)

Unit tests for this chart live under [`tests/`](tests/) and run with [helm-unittest](https://github.com/helm-unittest/helm-unittest).

## Install plugin

```bash
helm plugin install https://github.com/helm-unittest/helm-unittest --version v0.6.3 --verify=false
```

## Run tests

From the chart root:

```bash
helm unittest .
```

## Coverage

| Suite | Templates |
|-------|-----------|
| `deployment_test.yaml` | `deployment.yaml` |
| `configmap_test.yaml` | `configmap.yaml` |
| `service_test.yaml` | `service.yaml` |

Fixtures: [`tests/data/test_values.yaml`](data/test_values.yaml), [`tests/data/test_values_files.yaml`](data/test_values_files.yaml).

CI runs `helm lint` and `helm unittest .` on every pull request (see [`.github/workflows/ci.yml`](../.github/workflows/ci.yml)).

When you add or change a template or a values branch, add or update tests in the same change.
37 changes: 37 additions & 0 deletions tests/configmap_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: configmap
templates:
- configmap.yaml
tests:
- it: should render ConfigMap from legacy config.content
values:
- ./data/test_values.yaml
asserts:
- isKind:
of: ConfigMap
- matchRegex:
path: metadata.name
pattern: -config$
- matchRegex:
path: data["config.yaml"]
pattern: "name: example-probe"

- it: should include schema.yml when schemaContent is set
values:
- ./data/test_values.yaml
set:
config.schemaContent: 'version: "1"'
asserts:
- matchRegex:
path: data["schema.yml"]
pattern: 'version: "1"'

- it: should prefer config.files over legacy content
values:
- ./data/test_values_files.yaml
asserts:
- matchRegex:
path: data["agent.yml"]
pattern: "agent: custom"
- notExists:
path: data.config.yaml
37 changes: 37 additions & 0 deletions tests/data/test_values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
replicaCount: 1

workload:
kind: probe

image:
repository: ghcr.io/fluid-pub/probe-example
tag: "0.1.0"
pullPolicy: IfNotPresent

config:
files: {}
content: |
name: example-probe
schemaInImage: false
schemaContent: ""

configMount:
mountPath: /etc/fluid/config
fileName: config.yaml

credentialsSecret:
enabled: false
secretName: ""
mountPath: /etc/fluid/credentials
items: []

service:
enabled: false
type: ClusterIP
port: 8080

strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 0
28 changes: 28 additions & 0 deletions tests/data/test_values_files.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
replicaCount: 1

workload:
kind: agent

image:
repository: ghcr.io/fluid-pub/fluid-agent-example
tag: "0.1.0"
pullPolicy: IfNotPresent

config:
files:
agent.yml: |
agent: custom
content: |
ignored: true
schemaInImage: false
schemaContent: ""

configMount:
mountPath: /etc/fluid/config
fileName: config.yaml

credentialsSecret:
enabled: false

service:
enabled: false
81 changes: 81 additions & 0 deletions tests/deployment_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: deployment
templates:
- deployment.yaml
tests:
- it: should render Deployment with workload labels
values:
- ./data/test_values.yaml
asserts:
- isKind:
of: Deployment
- equal:
path: metadata.labels["fluid.io/workload-kind"]
value: probe
- equal:
path: spec.replicas
value: 1
- equal:
path: spec.template.spec.containers[0].image
value: ghcr.io/fluid-pub/probe-example:0.1.0

- it: should mount config directory when schemaInImage is false
values:
- ./data/test_values.yaml
asserts:
- equal:
path: spec.template.spec.containers[0].volumeMounts[0].mountPath
value: /etc/fluid/config
- notExists:
path: spec.template.spec.containers[0].volumeMounts[0].subPath

- it: should mount main config with subPath when schemaInImage is true and single file
values:
- ./data/test_values.yaml
set:
config.schemaInImage: true
asserts:
- equal:
path: spec.template.spec.containers[0].volumeMounts[0].mountPath
value: /etc/fluid/config/config.yaml
- equal:
path: spec.template.spec.containers[0].volumeMounts[0].subPath
value: config.yaml

- it: should not expose container ports when service is disabled
values:
- ./data/test_values.yaml
asserts:
- notExists:
path: spec.template.spec.containers[0].ports

- it: should expose container port when service is enabled
values:
- ./data/test_values.yaml
set:
service.enabled: true
service.port: 9090
asserts:
- equal:
path: spec.template.spec.containers[0].ports[0].containerPort
value: 9090

- it: should mount credentials secret when enabled
values:
- ./data/test_values.yaml
set:
credentialsSecret.enabled: true
credentialsSecret.secretName: probe-credentials
asserts:
- contains:
path: spec.template.spec.volumes
content:
name: credentials
secret:
secretName: probe-credentials
- contains:
path: spec.template.spec.containers[0].volumeMounts
content:
name: credentials
mountPath: /etc/fluid/credentials
readOnly: true
27 changes: 27 additions & 0 deletions tests/service_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: service
templates:
- service.yaml
tests:
- it: should not render Service when disabled
values:
- ./data/test_values.yaml
asserts:
- hasDocuments:
count: 0

- it: should render Service when enabled
values:
- ./data/test_values.yaml
set:
service.enabled: true
service.port: 8080
asserts:
- isKind:
of: Service
- equal:
path: spec.ports[0].port
value: 8080
- equal:
path: spec.ports[0].targetPort
value: http