You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
helm/cmd/helm/install_test.go

190 lines
6.7 KiB

/*
Copyright The Helm Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"testing"
)
func TestInstall(t *testing.T) {
tests := []cmdTestCase{
// Install, base case
{
name: "basic install",
cmd: "install aeneas testdata/testcharts/empty",
golden: "output/install.txt",
},
// Install, values from cli
{
name: "install with values",
cmd: "install virgil testdata/testcharts/alpine --set test.Name=bar",
golden: "output/install-with-values.txt",
},
// Install, values from cli via multiple --set
{
name: "install with multiple values",
cmd: "install virgil testdata/testcharts/alpine --set test.Color=yellow --set test.Name=banana",
golden: "output/install-with-multiple-values.txt",
},
// Install, values from yaml
{
name: "install with values file",
cmd: "install virgil testdata/testcharts/alpine -f testdata/testcharts/alpine/extra_values.yaml",
golden: "output/install-with-values-file.txt",
},
// Install, no hooks
{
name: "install without hooks",
cmd: "install aeneas testdata/testcharts/alpine --no-hooks --set test.Name=hello",
golden: "output/install-no-hooks.txt",
},
// Install, values from multiple yaml
{
name: "install with values",
cmd: "install virgil testdata/testcharts/alpine -f testdata/testcharts/alpine/extra_values.yaml -f testdata/testcharts/alpine/more_values.yaml",
golden: "output/install-with-multiple-values-files.txt",
},
// Install, no charts
{
name: "install with no chart specified",
cmd: "install",
golden: "output/install-no-args.txt",
wantError: true,
},
// Install, re-use name
{
name: "install and replace release",
cmd: "install aeneas testdata/testcharts/empty --replace",
golden: "output/install-and-replace.txt",
},
// Install, with timeout
{
name: "install with a timeout",
cmd: "install foobar testdata/testcharts/empty --timeout 120",
golden: "output/install-with-timeout.txt",
},
// Install, with wait
{
name: "install with a wait",
cmd: "install apollo testdata/testcharts/empty --wait",
golden: "output/install-with-wait.txt",
},
// Install, using the name-template
{
name: "install with name-template",
cmd: "install testdata/testcharts/empty --name-template '{{upper \"foobar\"}}'",
golden: "output/install-name-template.txt",
},
// Install, perform chart verification along the way.
{
name: "install with verification, missing provenance",
cmd: "install bogus testdata/testcharts/compressedchart-0.1.0.tgz --verify --keyring testdata/helm-test-key.pub",
wantError: true,
},
{
name: "install with verification, directory instead of file",
cmd: "install bogus testdata/testcharts/signtest --verify --keyring testdata/helm-test-key.pub",
wantError: true,
},
{
name: "install with verification, valid",
cmd: "install signtest testdata/testcharts/signtest-0.1.0.tgz --verify --keyring testdata/helm-test-key.pub",
},
// Install, chart with missing dependencies in /charts
{
name: "install chart with missing dependencies",
cmd: "install nodeps testdata/testcharts/chart-missing-deps",
wantError: true,
},
// Install, chart with bad dependencies in Chart.yaml in /charts
{
name: "install chart with bad dependencies in Chart.yaml",
cmd: "install badreq testdata/testcharts/chart-bad-requirements",
wantError: true,
},
// Install, chart with library chart dependency
{
name: "install chart with library chart dependency",
cmd: "install withlibchartp testdata/testcharts/chart-with-lib-dep",
},
// Install, library chart
{
name: "install library chart",
cmd: "install libchart testdata/testcharts/lib-chart",
wantError: true,
golden: "output/template-lib-chart.txt",
},
// Install, chart with bad type
{
name: "install chart with bad type",
cmd: "install badtype testdata/testcharts/chart-bad-type",
wantError: true,
golden: "output/install-chart-bad-type.txt",
},
Feat/schema validation (#5350) * Add the Schema type and a function to read it * Added a function to read a schema from a file * Check that values.yaml matches schema This commit uses the gojsonschema package to validate a values.yaml file against a corresponding values.schema.yaml file. * Add functionality to generate a schema from a values.yaml * Add Schema to Chart and loader * Clean up implementation in chartutil * Add tests for helm install with schema * Add schema validation to helm lint * Clean up "matchSchema" * Modify error output * Add documentation * Fix a linter issue * Fix a test that broke during a rebase * Clean up documentation * Specify JSONSchema spec Since JSONSchema is still in a draft state as of this commit, we need to specify a particular version of the JSONSchema spec * Switch to using builtin functionality for file extensions * Switch to using a third-party library for JSON conversion * Use the constants from the gojsonschema package * Updates to unit tests * Minor change to avoid string cast * Remove JSON Schema generation * Change Schema type from map[string]interface{} to []byte * Convert all Schema YAML to JSON * Fix some tests that were broken by a rebase * Fix up YAML/JSON conversions * This checks subcharts for schema validation The final coalesced values for a given chart will be validated against that chart's schema, as well as any dependent subchart's schema * Add unit tests for ValidateAgainstSchema * Remove nonessential test files * Remove a misleading unit test The TestReadSchema unit test was simply testing the ReadValues function, which is already being validated in the TestReadValues unit test * Update documentation to reflect changes to subchart schemas
6 years ago
// Install, values from yaml, schematized
{
name: "install with schema file",
cmd: "install schema testdata/testcharts/chart-with-schema",
golden: "output/schema.txt",
},
// Install, values from yaml, schematized with errors
{
name: "install with schema file, with errors",
cmd: "install schema testdata/testcharts/chart-with-schema-negative",
wantError: true,
golden: "output/schema-negative.txt",
},
// Install, values from yaml, extra values from yaml, schematized with errors
{
name: "install with schema file, extra values from yaml, with errors",
cmd: "install schema testdata/testcharts/chart-with-schema -f testdata/testcharts/chart-with-schema/extra-values.yaml",
wantError: true,
golden: "output/schema-negative.txt",
},
// Install, values from yaml, extra values from cli, schematized with errors
{
name: "install with schema file, extra values from cli, with errors",
cmd: "install schema testdata/testcharts/chart-with-schema --set age=-5",
wantError: true,
golden: "output/schema-negative-cli.txt",
},
// Install with subchart, values from yaml, schematized with errors
{
name: "install with schema file and schematized subchart, with errors",
cmd: "install schema testdata/testcharts/chart-with-schema-and-subchart",
wantError: true,
golden: "output/subchart-schema-negative.txt",
},
// Install with subchart, values from yaml, extra values from cli, schematized with errors
{
name: "install with schema file and schematized subchart, extra values from cli",
cmd: "install schema testdata/testcharts/chart-with-schema-and-subchart --set lastname=doe --set subchart-with-schema.age=25",
golden: "output/subchart-schema-cli.txt",
},
// Install with subchart, values from yaml, extra values from cli, schematized with errors
{
name: "install with schema file and schematized subchart, extra values from cli, with errors",
cmd: "install schema testdata/testcharts/chart-with-schema-and-subchart --set lastname=doe --set subchart-with-schema.age=-25",
wantError: true,
golden: "output/subchart-schema-cli-negative.txt",
},
}
runTestActionCmd(t, tests)
}