All Projects → lrills → Helm Unittest

lrills / Helm Unittest

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

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Helm Unittest

helm-unittest
BDD styled unit test framework for Kubernetes Helm charts as a Helm plugin.
Stars: ✭ 276 (+7.81%)
Mutual labels:  helm, unittest
acceptance-testing
Acceptance test suite for the Helm client
Stars: ✭ 22 (-91.41%)
Mutual labels:  helm
ckan-helm
Helm chart for CKAN
Stars: ✭ 15 (-94.14%)
Mutual labels:  helm
flekszible
Kubernetes resource/manifest file preprocessor, generator and manager.
Stars: ✭ 34 (-86.72%)
Mutual labels:  helm
big-bang
Big Bang is a declarative, continuous delivery tool for core DoD hardened and approved packages into a Kubernetes cluster.
Stars: ✭ 55 (-78.52%)
Mutual labels:  helm
TDengine-Operator
Setup TDengine on Kubenetes
Stars: ✭ 28 (-89.06%)
Mutual labels:  helm
core-dump-handler
Save core dumps from a Kubernetes Service or RedHat OpenShift to an S3 protocol compatible object store
Stars: ✭ 45 (-82.42%)
Mutual labels:  helm
homelab
My self-hosting infrastructure, fully automated from empty disk to operating services
Stars: ✭ 4,451 (+1638.67%)
Mutual labels:  helm
helm-github
Implement a Helm chart repository with GitHub pages
Stars: ✭ 18 (-92.97%)
Mutual labels:  helm
utx
对Python unittest的功能进行了扩展(用例排序,分组,数据驱动,可视化报告等)
Stars: ✭ 132 (-48.44%)
Mutual labels:  unittest
rudder
Application releases based on helm
Stars: ✭ 19 (-92.58%)
Mutual labels:  helm
helm-navi
Navigate headings and keywords provided by navi-mode and outshine using Helm
Stars: ✭ 13 (-94.92%)
Mutual labels:  helm
fake-sftp-server-rule
A JUnit rule that runs an in-memory SFTP server.
Stars: ✭ 34 (-86.72%)
Mutual labels:  unittest
jitsi-scalable-helm
Scalable jitsi helm chart
Stars: ✭ 28 (-89.06%)
Mutual labels:  helm
flask-rest-api
This program shows how to set up a flaskrestapi with postgre db, blueprint, sqlalchemy, marshmallow, wsgi, unittests
Stars: ✭ 28 (-89.06%)
Mutual labels:  unittest
MockDataGenerator
Generate mock data for POCO
Stars: ✭ 12 (-95.31%)
Mutual labels:  unittest
smag-mvp
Social Record - Distributed scraping and analysis pipeline for a range of social media platforms
Stars: ✭ 18 (-92.97%)
Mutual labels:  helm
chartcenter
The Central Helm Repository for the Community
Stars: ✭ 40 (-84.37%)
Mutual labels:  helm
Chart Releaser
Hosting Helm Charts via GitHub Pages and Releases
Stars: ✭ 253 (-1.17%)
Mutual labels:  helm
kubernetes-binaries-managers
Kubernetes related binaries manager.
Stars: ✭ 48 (-81.25%)
Mutual labels:  helm

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].