2016-06-23 02:28:45 +08:00
|
|
|
/*
|
2018-08-25 03:03:55 +08:00
|
|
|
Copyright The Helm Authors.
|
2016-06-23 02:28:45 +08:00
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-05-25 07:21:41 +08:00
|
|
|
package chartutil
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
2019-10-04 02:27:05 +08:00
|
|
|
"helm.sh/helm/v3/pkg/chart"
|
2016-05-25 07:21:41 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const testfile = "testdata/chartfiletest.yaml"
|
|
|
|
|
|
|
|
|
|
func TestLoadChartfile(t *testing.T) {
|
|
|
|
|
f, err := LoadChartfile(testfile)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Errorf("Failed to open %s: %s", testfile, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2016-12-02 23:07:58 +08:00
|
|
|
verifyChartfile(t, f, "frobnitz")
|
2016-05-25 07:21:41 +08:00
|
|
|
}
|
|
|
|
|
|
2016-12-02 23:07:58 +08:00
|
|
|
func verifyChartfile(t *testing.T, f *chart.Metadata, name string) {
|
2016-05-25 07:21:41 +08:00
|
|
|
|
2023-03-22 21:31:16 +08:00
|
|
|
if f == nil { //nolint:staticcheck
|
2016-06-02 07:02:32 +08:00
|
|
|
t.Fatal("Failed verifyChartfile because f is nil")
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-22 21:31:16 +08:00
|
|
|
if f.APIVersion != chart.APIVersionV1 { //nolint:staticcheck
|
2019-04-06 04:40:06 +08:00
|
|
|
t.Errorf("Expected API Version %q, got %q", chart.APIVersionV1, f.APIVersion)
|
2016-10-05 02:13:01 +08:00
|
|
|
}
|
|
|
|
|
|
2016-12-02 23:07:58 +08:00
|
|
|
if f.Name != name {
|
|
|
|
|
t.Errorf("Expected %s, got %s", name, f.Name)
|
2016-05-25 07:21:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if f.Description != "This is a frobnitz." {
|
|
|
|
|
t.Errorf("Unexpected description %q", f.Description)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if f.Version != "1.2.3" {
|
|
|
|
|
t.Errorf("Unexpected version %q", f.Version)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(f.Maintainers) != 2 {
|
|
|
|
|
t.Errorf("Expected 2 maintainers, got %d", len(f.Maintainers))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if f.Maintainers[0].Name != "The Helm Team" {
|
|
|
|
|
t.Errorf("Unexpected maintainer name.")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if f.Maintainers[1].Email != "nobody@example.com" {
|
|
|
|
|
t.Errorf("Unexpected maintainer email.")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(f.Sources) != 1 {
|
|
|
|
|
t.Fatalf("Unexpected number of sources")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if f.Sources[0] != "https://example.com/foo/bar" {
|
|
|
|
|
t.Errorf("Expected https://example.com/foo/bar, got %s", f.Sources)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if f.Home != "http://example.com" {
|
|
|
|
|
t.Error("Unexpected home.")
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-23 04:58:19 +08:00
|
|
|
if f.Icon != "https://example.com/64x64.png" {
|
|
|
|
|
t.Errorf("Unexpected icon: %q", f.Icon)
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-25 07:21:41 +08:00
|
|
|
if len(f.Keywords) != 3 {
|
|
|
|
|
t.Error("Unexpected keywords")
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-17 06:27:13 +08:00
|
|
|
if len(f.Annotations) != 2 {
|
|
|
|
|
t.Fatalf("Unexpected annotations")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if want, got := "extravalue", f.Annotations["extrakey"]; want != got {
|
|
|
|
|
t.Errorf("Want %q, but got %q", want, got)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if want, got := "anothervalue", f.Annotations["anotherkey"]; want != got {
|
|
|
|
|
t.Errorf("Want %q, but got %q", want, got)
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-25 07:21:41 +08:00
|
|
|
kk := []string{"frobnitz", "sprocket", "dodad"}
|
|
|
|
|
for i, k := range f.Keywords {
|
|
|
|
|
if kk[i] != k {
|
|
|
|
|
t.Errorf("Expected %q, got %q", kk[i], k)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-04-18 04:41:38 +08:00
|
|
|
|
|
|
|
|
func TestIsChartDir(t *testing.T) {
|
|
|
|
|
validChartDir, err := IsChartDir("testdata/frobnitz")
|
|
|
|
|
if !validChartDir {
|
|
|
|
|
t.Errorf("unexpected error while reading chart-directory: (%v)", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
validChartDir, err = IsChartDir("testdata")
|
|
|
|
|
if validChartDir || err == nil {
|
|
|
|
|
t.Errorf("expected error but did not get any")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|