2.1.5 • Published 1 year ago

@rophy123/helmtest v2.1.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

helmtest

A npm module which enables writing unit tests with nodejs / Jest.

Heavily inspired by Stono/helmtest.

Why not just use Stono/helmtest?

I originally wanted to update Stono/helmtest to fit my needs, but after attempting to customize it, I figured it's actually easier to rewrite one.

Differences with Stono/helmtest:

  • Single js file for the core logic (lib/helmtest.js)
  • Supports kubeconform instead of kubeval
  • No Grunt and TypeScript
  • Can be used as a npm library without assuming test framework and passing objects around global scope.
  • Can also run independently as CLI. In this case jest is bundled instead of mocha/chai.

Getting Started

Running helmtest as npm module

Install helmtest:

npm install @rophy123/helmtest

To use helmtest in your code:

const helmtest = require('@rophy123/helmtest');

// Run `helm template` under working directory
helmtest.renderTemplate()
.then(results => {
  // results are JS objects converted from result YAML.
  // '[{"apiVesrion":"v1","kind":"ServiceAccount","metadata":...
  console.log(JSON.stringify(results));
});

The results object can be used to verify details. For example, in jest:

const helmtest = require('@rophy123/helmtest');

test('exmapleChart should render 4 resources', async () => {
  const result = await helmtest.renderTemplate();
  expect(result.length).toBe(4);
});

See API Spec for the options of helmtest.renderTemplate().

Running helmtest as CLI

Install jest along with helmtest globally:

npm install -g @rophy123/helmtest jest

...and then you can write unit tests under tests/ dir of your chart project without the need for package.json

A docker image rophy/helmtest is avilable which includes everything to run up unit tests.

See example as an example helm chart project on how to use docker image and write unit tests.

API Spec

helmtest currently only expose one method: helmtest.renderTemplate(options).

options is a object with option names, descriptions and defaults as below:

OptionDescriptionDefault
chartDirPath to chart, the CHART arg in helm CLI: helm template [NAME] [CHART] [flags].'.'
releaseNameRelease name, the NAME arg in helm CLI: helm template [NAME] [CHART] [flags].'release-name'
valuesMap of chart values to set.{}
valuesFilesPaths to additional values.yaml.[]
templateFilesRender only listed template files, e.g. ['templates/hpa.yaml'][]
extraHelmArgsExtra args to pass to helm CLI, e.g. --timeout=5s[]
helmBinaryPath to helm binary.process.env.HELM_BINARY \|\| 'helm'
loadYamlif false, will return rendered template as raw string instead of js object.true
kubeconformEnabledif true, will pass rendered template to kubeconform CLI to validate schema.process.env.KUBECONFORM_ENABLED \|\| false
kubeconformBinaryPath to kubeconform binary.process.env.KUBECONFORM_BINARY \|\| 'kubeconform'
kubeconformArgsArgs to pass to kubeconform CLI. Will append process.env.KUBECONFORM_EXTRA_ARGS.['-strict','-summary']
2.1.5

1 year ago

2.1.4

1 year ago

2.1.3

1 year ago

2.1.2

1 year ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago