All Projects → helm-unittest → helm-unittest

helm-unittest / helm-unittest

Licence: MIT License
BDD styled unit test framework for Kubernetes Helm charts as a Helm plugin.

Programming Languages

go
31211 projects - #10 most used programming language
shell
77523 projects
Mustache
554 projects
Makefile
30231 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to helm-unittest

hull
The incredible HULL - Helm Uniform Layer Library - is a Helm library chart to improve Helm chart based workflows
Stars: ✭ 66 (-76.09%)
Mutual labels:  helm, helm-plugin, helm-chart
kubehelper
KubeHelper - simplifies many daily Kubernetes cluster tasks through a web interface. Search, analysis, run commands, cron jobs, reports, filters, git synchronization and many more.
Stars: ✭ 200 (-27.54%)
Mutual labels:  helm, helm-chart
helm-backup
Helm plugin which performs backup/restore of releases in a namespace to/from a file
Stars: ✭ 70 (-74.64%)
Mutual labels:  helm, helm-plugin
aks-multi-tenant-agic
This sample shows how to use the Application Gateway Ingress Controller in a multi-tenant AKS cluster to expose multiple instances of the same application, one for each tenant.
Stars: ✭ 27 (-90.22%)
Mutual labels:  helm, helm-chart
helm-namespace
Namespace auto-creation for Helm 3
Stars: ✭ 29 (-89.49%)
Mutual labels:  helm, helm-plugin
charts
Helm charts for creating reproducible and maintainable deployments of Polyaxon with Kubernetes.
Stars: ✭ 32 (-88.41%)
Mutual labels:  helm, helm-chart
helm-starter
A helm plugin for managing chart starters.
Stars: ✭ 32 (-88.41%)
Mutual labels:  helm, helm-plugin
helm-spray
Helm plugin for installing or upgrading sub-charts from an umbrella-chart using dependency orders
Stars: ✭ 64 (-76.81%)
Mutual labels:  helm, helm-plugin
pulsar-helm-chart
Official Apache Pulsar Helm Chart
Stars: ✭ 122 (-55.8%)
Mutual labels:  helm, helm-chart
helm-mapkubeapis
This is a Helm plugin which map deprecated or removed Kubernetes APIs in a release to supported APIs
Stars: ✭ 287 (+3.99%)
Mutual labels:  helm, helm-plugin
kube-karp
☸ Add a floating virtual IP to Kubernetes cluster nodes for load balancing easily.
Stars: ✭ 104 (-62.32%)
Mutual labels:  helm, helm-chart
litmus-helm
Helm Charts for the Litmus Chaos Operator & CRDs
Stars: ✭ 23 (-91.67%)
Mutual labels:  helm, helm-chart
helm-whatup
A Helm plugin to help users determine if there's an update available for their installed charts.
Stars: ✭ 37 (-86.59%)
Mutual labels:  helm, helm-plugin
helm-inject
Inject additional configurations during Helm upgrade
Stars: ✭ 17 (-93.84%)
Mutual labels:  helm, helm-plugin
helm-zabbix
Helm Chart For Zabbix
Stars: ✭ 56 (-79.71%)
Mutual labels:  helm, helm-chart
helm-schema-gen
So that you don't have to write values.schema.json by hand from scratch for your Helm 3 charts. [CURRENTLY NOT MAINTAINED]
Stars: ✭ 104 (-62.32%)
Mutual labels:  helm, helm-plugin
helm-charts
Source & Repo of https://charts.kubesphere.io/main & https://charts.kubesphere.io/test
Stars: ✭ 85 (-69.2%)
Mutual labels:  helm, helm-chart
helm-certgen
Helm plugin for generation of TLS certificates
Stars: ✭ 15 (-94.57%)
Mutual labels:  helm, helm-plugin
thunder
REST API application that manages user databases
Stars: ✭ 22 (-92.03%)
Mutual labels:  helm, helm-chart
helm-github
A Helm plugin to install raw Helm Charts from Github
Stars: ✭ 54 (-80.43%)
Mutual labels:  helm, helm-plugin

THIS REPOSITORY IS NOT MAINTAINED ANYMORE.

You can consider other working forks like quintush/helm-unittest. If anyone would like to continue maintaining this repo, please mail [email protected]. I'd be glad to transfer ownership and see it live again.

helm unittest

Unit test for helm chart in YAML to keep your chart consistent and robust!

Feature:

Documentation

If you are ready for writing tests, check the DOCUMENT for the test API in YAML.

Install

$ helm plugin install https://github.com/lrills/helm-unittest

It will install the latest version of binary into helm plugin directory.

Get Started

Add tests in .helmignore of your chart, and create the following test file at $YOUR_CHART/tests/deployment_test.yaml:

suite: test deployment
templates:
  - deployment.yaml
tests:
  - it: should work
    set:
      image.tag: latest
    asserts:
      - isKind:
          of: Deployment
      - matchRegex:
          path: metadata.name
          pattern: -my-chart$
      - equal:
          path: spec.template.spec.containers[0].image
          value: nginx:latest

and run:

$ helm unittest $YOUR_CHART

Now there is your first test! ;)

Test Suite File

The test suite file is written in pure YAML, and default placed under the tests/ directory of the chart with suffix _test.yaml. You can also have your own suite files arrangement with -f, --file option of cli set as the glob patterns of test suite files related to chart directory, like:

$ helm unittest -f 'my-tests/*.yaml' -f 'more-tests/*.yaml' my-chart

Check DOCUMENT for more details about writing tests.

Usage

$ helm unittest [flags] CHART [...]

This renders your charts locally (without tiller) and runs tests defined in test suite files.

Flags

--color              enforce printing colored output even stdout is not a tty. Set to false to disable color
-f, --file stringArray   glob paths of test files location, default to tests/*_test.yaml (default [tests/*_test.yaml])
-h, --help               help for unittest
-u, --update-snapshot    update the snapshot cached if needed, make sure you review the change before update

Example

Check __fixtures__/basic/ for some basic use cases of a simple chart.

Snapshot Testing

Sometimes you may just want to keep the rendered manifest not changed between changes without every details asserted. That's the reason for snapshot testing! Check the tests below:

templates:
  - deployment.yaml
tests:
  - it: pod spec should match snapshot
    asserts:
      - matchSnapshot:
          path: spec.template.spec
  # or you can snapshot the whole manifest
  - it: manifest should match snapshot
    asserts:
      - matchSnapshot: {}

The matchSnapshot assertion validate the content rendered the same as cached last time. It fails if the content changed, and you should check and update the cache with -u, --update-snapshot option of cli.

$ helm unittest -u my-chart

The cache files is stored as __snapshot__/*_test.yaml.snap at the directory your test file placed, you should add them in version control with your chart.

Tests within subchart

If you have customized subchart (not installed via helm dependency) existed in charts directory, tests inside would also be executed by default. You can disable this behavior by setting --with-subchart=false flag in cli, thus only the tests in root chart will be executed. Notice that the values defined in subchart tests will be automatically scoped, you don't have to add dependency scope yourself:

# parent-chart/charts/child-chart/tests/xxx_test.yaml
templates:
  - xxx.yaml
tests:
  - it:
    set:
      # no need to prefix with "child-chart."
      somevalue: should_be_scoped
    asserts:
      - ...

Check __fixtures__/with-subchart/ as an example.

Related Projects / Commands

This plugin is inspired by helm-template, and the idea of snapshot testing and some printing format comes from jest.

And there are some other helm commands you might want to use:

  • helm template: render the chart and print the output.

  • helm lint: examines a chart for possible issues, useful to validate chart dependencies.

  • helm test: test a release with testing pod defined in chart. Note this does create resources on your cluster to verify if your release is correct. Check the doc.

License

MIT

Contributing

Issues and PRs are welcome!
Before start developing this plugin, you must have go and dep installed, and run:

git clone [email protected]:lrills/helm-unittest.git
cd helm-unittest
dep ensure

And please make CI passed when request a PR which would check following things:

  • dep status passed. Make sure you run dep ensure if new dependencies added.
  • gofmt no changes needed. Please run gofmt -w -s before you commit.
  • go test ./unittest/... passed.

In some cases you might need to manually fix the tests in *_test.go. If the snapshot tests (of the plugin's test code) failed you need to run:

UPDATE_SNAPSHOTS=true go test ./unittest/...

This update the snapshot cache file and please add them before you commit.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].