From d8a5c5b0266a18df200edb7f1a9d450d560f1197 Mon Sep 17 00:00:00 2001 From: "Jiravesayakul, Kornchanok (Agoda)" Date: Mon, 16 Jul 2018 00:31:38 +0700 Subject: [PATCH 1/2] Fix multi-chart --- README.md | 4 ++-- lib/app.js | 2 +- lib/helm.js | 25 +++++++++++-------------- test/helm.js | 2 +- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 47d4245..a66308f 100644 --- a/README.md +++ b/README.md @@ -33,12 +33,12 @@ There are some global helper variables defined for use in your tests: #### helm This is the root context and exposes the following functions: - - `withValueFile([chartName/]path)`: Specify a value file to use when running helm, relative to the root of your chart. You can call this multiple times + - `withValueFile(path, [chartName])`: Specify a value file to use when running helm, relative to the root of your chart. You can call this multiple times - `set(key, value)`: Allows you to override a specific value, for example `set('service.port', '80')` would do `--set service.port=80` when running helm - `go(done, [chartName])`: Run a helm template generation and parse the output - `lint(done, [chartName])`: Run a helm lint - *`chartName` is an optional parameter but if you want to run helm-test on main folder (against all charts), you need to specify 'chartName'* + *`chartName` is an optional parameter but if you want to run helm-test on main folder (against all charts), you need to define 'chartName'* #### yaml This global helper function allows you to parse yaml using `yamljs`. This is useful for scenarios like a configmap containing a string block which sub contains yaml, that you wish to assert on. diff --git a/lib/app.js b/lib/app.js index 1e5dcf1..86b2084 100644 --- a/lib/app.js +++ b/lib/app.js @@ -12,7 +12,7 @@ module.exports = function App(exec) { let pattern = 'tests' if(options.all) { globals = path.join(__dirname, 'all-globals.js'); - pattern = './**/tests/*.js'; + pattern = './**/tests/**/*.js'; } let watch = ''; if(options.watch) { diff --git a/lib/helm.js b/lib/helm.js index 6ec9311..b082654 100644 --- a/lib/helm.js +++ b/lib/helm.js @@ -64,14 +64,12 @@ module.exports = function Helm(exec, chartPath) { let self = {}; let files = []; let sets = []; - self.withValueFile = function(valueFile) { - if (chartPath) { - let paths = valueFile.split('/'); - if (paths.length > 1) { - valueFile = paths[1]; - } + self.withValueFile = function(valueFile, chartName) { + let pathToValueFile = path.join(process.cwd(), valueFile); + if (!chartPath && chartName) { + pathToValueFile = path.join(process.cwd(), chartName, valueFile); } - const pathToValueFile = path.join(process.cwd(), valueFile); + files.push(pathToValueFile); return self; }; @@ -79,10 +77,9 @@ module.exports = function Helm(exec, chartPath) { sets.push(key + '=' + value); return self; }; - self.go = function(done, path) { - path = chartPath || path || '.'; - let command = `helm template ${path}`; - console.log(files.join(' -f ')); + self.go = function(done, chartName) { + chartName = chartPath || chartName || '.'; + let command = `helm template ${chartName}`; if(files.length > 0) { command = command + ' -f ' + files.join(' -f '); } @@ -96,9 +93,9 @@ module.exports = function Helm(exec, chartPath) { exec.command(command, options, helmResultParser.parse(done)); return self; }; - self.lint = function(done, path) { - path = chartPath || path || '.'; - let command = `helm lint ${path}`; + self.lint = function(done, chartName) { + chartName = chartPath || chartName || '.'; + let command = `helm lint ${chartName}`; const options = { output: true }; exec.command(command, options, helmResultParser.parse(done)); diff --git a/test/helm.js b/test/helm.js index 62e0a73..0195b5d 100644 --- a/test/helm.js +++ b/test/helm.js @@ -27,7 +27,7 @@ describe('Helm', () => { helm = new Helm(exec); }); it('should accept value files', () => { - helm.withValueFile('chart-name/some-file.yaml'); + helm.withValueFile('some-file.yaml', 'chart-name'); }); it('should run a helm template', done => { helm.go(done, 'chart-name'); From dea7e955d66aede0f757d02d712701f3196cbaa0 Mon Sep 17 00:00:00 2001 From: "Jiravesayakul, Kornchanok (Agoda)" Date: Mon, 16 Jul 2018 10:10:17 +0700 Subject: [PATCH 2/2] Add remains --- bin/helm-test | 4 +++- lib/all-globals.js | 5 +++++ lib/globals.js | 2 +- package.json | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 lib/all-globals.js diff --git a/bin/helm-test b/bin/helm-test index d6f7e61..86eb4e4 100755 --- a/bin/helm-test +++ b/bin/helm-test @@ -12,10 +12,12 @@ const program = require('commander'); program .version(version) .option('-w, --watch', 'Watch for file changes and re-run tests') + .option('-a, --all', 'Run test against all charts') .parse(process.argv); app.test({ - watch: program.watch + watch: program.watch, + all: program.all }, err => { logger.log('Finished.'); if(err) { diff --git a/lib/all-globals.js b/lib/all-globals.js new file mode 100644 index 0000000..38758cb --- /dev/null +++ b/lib/all-globals.js @@ -0,0 +1,5 @@ +'use strict'; +const exec = new require('./exec')(); +const Helm = require('./helm'); +global.helm = new Helm(exec); +global.yaml = require('yamljs'); diff --git a/lib/globals.js b/lib/globals.js index 38758cb..74ecb9c 100644 --- a/lib/globals.js +++ b/lib/globals.js @@ -1,5 +1,5 @@ 'use strict'; const exec = new require('./exec')(); const Helm = require('./helm'); -global.helm = new Helm(exec); +global.helm = new Helm(exec, '.'); global.yaml = require('yamljs'); diff --git a/package.json b/package.json index 2b70e05..0b3d958 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "helm-test", "description": "A CLI to test Helm charts", - "version": "0.1.18", + "version": "0.1.19", "homepage": "https://github.com/Stono/helm-test", "author": { "name": "Karl Stoney",