github.com/stefanmcshane/helm@v0.0.0-20221213002717-88a4a2c6e77d/pkg/chartutil/chartfile_test.go (about)

     1  /*
     2  Copyright The Helm Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package chartutil
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/stefanmcshane/helm/pkg/chart"
    23  )
    24  
    25  const testfile = "testdata/chartfiletest.yaml"
    26  
    27  func TestLoadChartfile(t *testing.T) {
    28  	f, err := LoadChartfile(testfile)
    29  	if err != nil {
    30  		t.Errorf("Failed to open %s: %s", testfile, err)
    31  		return
    32  	}
    33  	verifyChartfile(t, f, "frobnitz")
    34  }
    35  
    36  func verifyChartfile(t *testing.T, f *chart.Metadata, name string) {
    37  
    38  	if f == nil {
    39  		t.Fatal("Failed verifyChartfile because f is nil")
    40  	}
    41  
    42  	if f.APIVersion != chart.APIVersionV1 {
    43  		t.Errorf("Expected API Version %q, got %q", chart.APIVersionV1, f.APIVersion)
    44  	}
    45  
    46  	if f.Name != name {
    47  		t.Errorf("Expected %s, got %s", name, f.Name)
    48  	}
    49  
    50  	if f.Description != "This is a frobnitz." {
    51  		t.Errorf("Unexpected description %q", f.Description)
    52  	}
    53  
    54  	if f.Version != "1.2.3" {
    55  		t.Errorf("Unexpected version %q", f.Version)
    56  	}
    57  
    58  	if len(f.Maintainers) != 2 {
    59  		t.Errorf("Expected 2 maintainers, got %d", len(f.Maintainers))
    60  	}
    61  
    62  	if f.Maintainers[0].Name != "The Helm Team" {
    63  		t.Errorf("Unexpected maintainer name.")
    64  	}
    65  
    66  	if f.Maintainers[1].Email != "nobody@example.com" {
    67  		t.Errorf("Unexpected maintainer email.")
    68  	}
    69  
    70  	if len(f.Sources) != 1 {
    71  		t.Fatalf("Unexpected number of sources")
    72  	}
    73  
    74  	if f.Sources[0] != "https://example.com/foo/bar" {
    75  		t.Errorf("Expected https://example.com/foo/bar, got %s", f.Sources)
    76  	}
    77  
    78  	if f.Home != "http://example.com" {
    79  		t.Error("Unexpected home.")
    80  	}
    81  
    82  	if f.Icon != "https://example.com/64x64.png" {
    83  		t.Errorf("Unexpected icon: %q", f.Icon)
    84  	}
    85  
    86  	if len(f.Keywords) != 3 {
    87  		t.Error("Unexpected keywords")
    88  	}
    89  
    90  	if len(f.Annotations) != 2 {
    91  		t.Fatalf("Unexpected annotations")
    92  	}
    93  
    94  	if want, got := "extravalue", f.Annotations["extrakey"]; want != got {
    95  		t.Errorf("Want %q, but got %q", want, got)
    96  	}
    97  
    98  	if want, got := "anothervalue", f.Annotations["anotherkey"]; want != got {
    99  		t.Errorf("Want %q, but got %q", want, got)
   100  	}
   101  
   102  	kk := []string{"frobnitz", "sprocket", "dodad"}
   103  	for i, k := range f.Keywords {
   104  		if kk[i] != k {
   105  			t.Errorf("Expected %q, got %q", kk[i], k)
   106  		}
   107  	}
   108  }
   109  
   110  func TestIsChartDir(t *testing.T) {
   111  	validChartDir, err := IsChartDir("testdata/frobnitz")
   112  	if !validChartDir {
   113  		t.Errorf("unexpected error while reading chart-directory: (%v)", err)
   114  		return
   115  	}
   116  	validChartDir, err = IsChartDir("testdata")
   117  	if validChartDir || err == nil {
   118  		t.Errorf("expected error but did not get any")
   119  		return
   120  	}
   121  }