From 0aa0de739e9e54357d4cc1773f32f49a7a32cdfc Mon Sep 17 00:00:00 2001 From: Anshul Verma Date: Mon, 2 Dec 2019 20:52:16 +0530 Subject: [PATCH] Fixes #6713 Friedly error message Signed-off-by: Anshul Verma --- pkg/chart/loader/load_test.go | 6 +++--- pkg/chart/metadata.go | 2 +- pkg/chart/metadata_test.go | 27 +++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100755 pkg/chart/metadata_test.go diff --git a/pkg/chart/loader/load_test.go b/pkg/chart/loader/load_test.go index 6576002eb..e5e9c0c62 100644 --- a/pkg/chart/loader/load_test.go +++ b/pkg/chart/loader/load_test.go @@ -194,7 +194,7 @@ icon: https://example.com/64x64.png if _, err = LoadFiles([]*BufferedFile{}); err == nil { t.Fatal("Expected err to be non-nil") } - if err.Error() != "validation: chart.metadata is required" { + if err.Error() != "validation: No such Chart found" { t.Errorf("Expected chart metadata missing error, got '%s'", err.Error()) } } @@ -268,7 +268,7 @@ func TestLoadInvalidArchive(t *testing.T) { {"illegal-name.tgz", "./.", "chart illegally contains content outside the base directory"}, {"illegal-name2.tgz", "/./.", "chart illegally contains content outside the base directory"}, {"illegal-name3.tgz", "missing-leading-slash", "chart illegally contains content outside the base directory"}, - {"illegal-name4.tgz", "/missing-leading-slash", "validation: chart.metadata is required"}, + {"illegal-name4.tgz", "/missing-leading-slash", "validation: No such Chart found"}, {"illegal-abspath.tgz", "//foo", "chart illegally contains absolute paths"}, {"illegal-abspath2.tgz", "///foo", "chart illegally contains absolute paths"}, {"illegal-abspath3.tgz", "\\\\foo", "chart illegally contains absolute paths"}, @@ -302,7 +302,7 @@ func TestLoadInvalidArchive(t *testing.T) { illegalChart = filepath.Join(tmpdir, "abs-path2.tgz") writeTar(illegalChart, "files/whatever.yaml", []byte("hello: world")) _, err = Load(illegalChart) - if err.Error() != "validation: chart.metadata is required" { + if err.Error() != "validation: No such Chart foundg" { t.Error(err) } diff --git a/pkg/chart/metadata.go b/pkg/chart/metadata.go index 96a3965b9..5d5207d10 100644 --- a/pkg/chart/metadata.go +++ b/pkg/chart/metadata.go @@ -67,7 +67,7 @@ type Metadata struct { // Validate checks the metadata for known issues, returning an error if metadata is not correct func (md *Metadata) Validate() error { if md == nil { - return ValidationError("chart.metadata is required") + return ValidationError("No such Chart found") } if md.APIVersion == "" { return ValidationError("chart.metadata.apiVersion is required") diff --git a/pkg/chart/metadata_test.go b/pkg/chart/metadata_test.go new file mode 100755 index 000000000..db4524c07 --- /dev/null +++ b/pkg/chart/metadata_test.go @@ -0,0 +1,27 @@ +/* +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 chart + +import "testing" + +func TestValidate(t *testing.T) { + var metadata *Metadata = nil + error := metadata.Validate() + errorMessage := "validation: No such Chart found" + if error.Error() != errorMessage { + t.Errorf("The error message is other than '%s'", errorMessage) + } +}