From e97ec089920a9d7c1cd9723bed31a89bca535166 Mon Sep 17 00:00:00 2001 From: Ian Howell Date: Wed, 27 Feb 2019 12:39:21 -0600 Subject: [PATCH] Add tests for helm install with schema Signed-off-by: Ian Howell --- cmd/helm/install_test.go | 27 +++++++++++ .../testdata/output/schema-negative-cli.txt | 3 ++ cmd/helm/testdata/output/schema-negative.txt | 4 ++ cmd/helm/testdata/output/schema.txt | 5 +++ .../chart-with-schema-negative/Chart.yaml | 6 +++ .../chart-with-schema-negative/README.md | 3 ++ .../templates/empty.yaml | 1 + .../values.schema.yaml | 45 +++++++++++++++++++ .../chart-with-schema-negative/values.yaml | 14 ++++++ .../testcharts/chart-with-schema/Chart.yaml | 6 +++ .../testcharts/chart-with-schema/README.md | 3 ++ .../chart-with-schema/extra-values.yaml | 2 + .../chart-with-schema/templates/empty.yaml | 1 + .../chart-with-schema/values.schema.yaml | 45 +++++++++++++++++++ .../testcharts/chart-with-schema/values.yaml | 17 +++++++ 15 files changed, 182 insertions(+) create mode 100644 cmd/helm/testdata/output/schema-negative-cli.txt create mode 100644 cmd/helm/testdata/output/schema-negative.txt create mode 100644 cmd/helm/testdata/output/schema.txt create mode 100644 cmd/helm/testdata/testcharts/chart-with-schema-negative/Chart.yaml create mode 100644 cmd/helm/testdata/testcharts/chart-with-schema-negative/README.md create mode 100644 cmd/helm/testdata/testcharts/chart-with-schema-negative/templates/empty.yaml create mode 100644 cmd/helm/testdata/testcharts/chart-with-schema-negative/values.schema.yaml create mode 100644 cmd/helm/testdata/testcharts/chart-with-schema-negative/values.yaml create mode 100644 cmd/helm/testdata/testcharts/chart-with-schema/Chart.yaml create mode 100644 cmd/helm/testdata/testcharts/chart-with-schema/README.md create mode 100644 cmd/helm/testdata/testcharts/chart-with-schema/extra-values.yaml create mode 100644 cmd/helm/testdata/testcharts/chart-with-schema/templates/empty.yaml create mode 100644 cmd/helm/testdata/testcharts/chart-with-schema/values.schema.yaml create mode 100644 cmd/helm/testdata/testcharts/chart-with-schema/values.yaml diff --git a/cmd/helm/install_test.go b/cmd/helm/install_test.go index 05ec6ea1a..b32400c5f 100644 --- a/cmd/helm/install_test.go +++ b/cmd/helm/install_test.go @@ -136,6 +136,33 @@ func TestInstall(t *testing.T) { wantError: true, golden: "output/install-chart-bad-type.txt", }, + // 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", + }, } runTestActionCmd(t, tests) diff --git a/cmd/helm/testdata/output/schema-negative-cli.txt b/cmd/helm/testdata/output/schema-negative-cli.txt new file mode 100644 index 000000000..15652464a --- /dev/null +++ b/cmd/helm/testdata/output/schema-negative-cli.txt @@ -0,0 +1,3 @@ +Error: .Values does not meet the specification of values.schema.yaml . see errors : +- age: Must be greater than or equal to 0/1 + diff --git a/cmd/helm/testdata/output/schema-negative.txt b/cmd/helm/testdata/output/schema-negative.txt new file mode 100644 index 000000000..a56ea190f --- /dev/null +++ b/cmd/helm/testdata/output/schema-negative.txt @@ -0,0 +1,4 @@ +Error: .Values does not meet the specification of values.schema.yaml . see errors : +- (root): employmentInfo is required +- age: Must be greater than or equal to 0/1 + diff --git a/cmd/helm/testdata/output/schema.txt b/cmd/helm/testdata/output/schema.txt new file mode 100644 index 000000000..a49622b2b --- /dev/null +++ b/cmd/helm/testdata/output/schema.txt @@ -0,0 +1,5 @@ +NAME: schema +LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC +NAMESPACE: default +STATUS: deployed + diff --git a/cmd/helm/testdata/testcharts/chart-with-schema-negative/Chart.yaml b/cmd/helm/testdata/testcharts/chart-with-schema-negative/Chart.yaml new file mode 100644 index 000000000..0e97f247c --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-with-schema-negative/Chart.yaml @@ -0,0 +1,6 @@ +description: Empty testing chart +home: https://k8s.io/helm +name: empty +sources: +- https://github.com/kubernetes/helm +version: 0.1.0 diff --git a/cmd/helm/testdata/testcharts/chart-with-schema-negative/README.md b/cmd/helm/testdata/testcharts/chart-with-schema-negative/README.md new file mode 100644 index 000000000..ed73c1797 --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-with-schema-negative/README.md @@ -0,0 +1,3 @@ +#Empty + +This space intentionally left blank. diff --git a/cmd/helm/testdata/testcharts/chart-with-schema-negative/templates/empty.yaml b/cmd/helm/testdata/testcharts/chart-with-schema-negative/templates/empty.yaml new file mode 100644 index 000000000..c80812f6e --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-with-schema-negative/templates/empty.yaml @@ -0,0 +1 @@ +# This file is intentionally blank diff --git a/cmd/helm/testdata/testcharts/chart-with-schema-negative/values.schema.yaml b/cmd/helm/testdata/testcharts/chart-with-schema-negative/values.schema.yaml new file mode 100644 index 000000000..2c8345c35 --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-with-schema-negative/values.schema.yaml @@ -0,0 +1,45 @@ +title: Values +type: object +properties: + firstname: + description: First name + type: string + lastname: + type: string + likesCoffee: + type: boolean + age: + description: Age + type: integer + minimum: 0 + employmentInfo: + type: object + properties: + salary: + type: number + minimum: 0 + title: + type: string + required: + - salary + addresses: + description: List of addresses + type: array + items: + type: object + properties: + city: + type: string + street: + type: string + number: + type: number + phoneNumbers: + type: array + items: + type: string +required: + - firstname + - lastname + - addresses + - employmentInfo diff --git a/cmd/helm/testdata/testcharts/chart-with-schema-negative/values.yaml b/cmd/helm/testdata/testcharts/chart-with-schema-negative/values.yaml new file mode 100644 index 000000000..5a1250bff --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-with-schema-negative/values.yaml @@ -0,0 +1,14 @@ +firstname: John +lastname: Doe +age: -5 +likesCoffee: true +addresses: + - city: Springfield + street: Main + number: 12345 + - city: New York + street: Broadway + number: 67890 +phoneNumbers: + - "(888) 888-8888" + - "(555) 555-5555" diff --git a/cmd/helm/testdata/testcharts/chart-with-schema/Chart.yaml b/cmd/helm/testdata/testcharts/chart-with-schema/Chart.yaml new file mode 100644 index 000000000..0e97f247c --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-with-schema/Chart.yaml @@ -0,0 +1,6 @@ +description: Empty testing chart +home: https://k8s.io/helm +name: empty +sources: +- https://github.com/kubernetes/helm +version: 0.1.0 diff --git a/cmd/helm/testdata/testcharts/chart-with-schema/README.md b/cmd/helm/testdata/testcharts/chart-with-schema/README.md new file mode 100644 index 000000000..ed73c1797 --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-with-schema/README.md @@ -0,0 +1,3 @@ +#Empty + +This space intentionally left blank. diff --git a/cmd/helm/testdata/testcharts/chart-with-schema/extra-values.yaml b/cmd/helm/testdata/testcharts/chart-with-schema/extra-values.yaml new file mode 100644 index 000000000..76c290c4f --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-with-schema/extra-values.yaml @@ -0,0 +1,2 @@ +age: -5 +employmentInfo: null diff --git a/cmd/helm/testdata/testcharts/chart-with-schema/templates/empty.yaml b/cmd/helm/testdata/testcharts/chart-with-schema/templates/empty.yaml new file mode 100644 index 000000000..c80812f6e --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-with-schema/templates/empty.yaml @@ -0,0 +1 @@ +# This file is intentionally blank diff --git a/cmd/helm/testdata/testcharts/chart-with-schema/values.schema.yaml b/cmd/helm/testdata/testcharts/chart-with-schema/values.schema.yaml new file mode 100644 index 000000000..2c8345c35 --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-with-schema/values.schema.yaml @@ -0,0 +1,45 @@ +title: Values +type: object +properties: + firstname: + description: First name + type: string + lastname: + type: string + likesCoffee: + type: boolean + age: + description: Age + type: integer + minimum: 0 + employmentInfo: + type: object + properties: + salary: + type: number + minimum: 0 + title: + type: string + required: + - salary + addresses: + description: List of addresses + type: array + items: + type: object + properties: + city: + type: string + street: + type: string + number: + type: number + phoneNumbers: + type: array + items: + type: string +required: + - firstname + - lastname + - addresses + - employmentInfo diff --git a/cmd/helm/testdata/testcharts/chart-with-schema/values.yaml b/cmd/helm/testdata/testcharts/chart-with-schema/values.yaml new file mode 100644 index 000000000..042dea664 --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-with-schema/values.yaml @@ -0,0 +1,17 @@ +firstname: John +lastname: Doe +age: 25 +likesCoffee: true +employmentInfo: + title: Software Developer + salary: 100000 +addresses: + - city: Springfield + street: Main + number: 12345 + - city: New York + street: Broadway + number: 67890 +phoneNumbers: + - "(888) 888-8888" + - "(555) 555-5555"