github.com/umeshredd/helm@v3.0.0-alpha.1+incompatible/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  	"helm.sh/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  	// Api instead of API because it was generated via protobuf.
    43  	if f.APIVersion != chart.APIVersionV1 {
    44  		t.Errorf("Expected API Version %q, got %q", chart.APIVersionV1, f.APIVersion)
    45  	}
    46  
    47  	if f.Name != name {
    48  		t.Errorf("Expected %s, got %s", name, f.Name)
    49  	}
    50  
    51  	if f.Description != "This is a frobnitz." {
    52  		t.Errorf("Unexpected description %q", f.Description)
    53  	}
    54  
    55  	if f.Version != "1.2.3" {
    56  		t.Errorf("Unexpected version %q", f.Version)
    57  	}
    58  
    59  	if len(f.Maintainers) != 2 {
    60  		t.Errorf("Expected 2 maintainers, got %d", len(f.Maintainers))
    61  	}
    62  
    63  	if f.Maintainers[0].Name != "The Helm Team" {
    64  		t.Errorf("Unexpected maintainer name.")
    65  	}
    66  
    67  	if f.Maintainers[1].Email != "nobody@example.com" {
    68  		t.Errorf("Unexpected maintainer email.")
    69  	}
    70  
    71  	if len(f.Sources) != 1 {
    72  		t.Fatalf("Unexpected number of sources")
    73  	}
    74  
    75  	if f.Sources[0] != "https://example.com/foo/bar" {
    76  		t.Errorf("Expected https://example.com/foo/bar, got %s", f.Sources)
    77  	}
    78  
    79  	if f.Home != "http://example.com" {
    80  		t.Error("Unexpected home.")
    81  	}
    82  
    83  	if f.Icon != "https://example.com/64x64.png" {
    84  		t.Errorf("Unexpected icon: %q", f.Icon)
    85  	}
    86  
    87  	if len(f.Keywords) != 3 {
    88  		t.Error("Unexpected keywords")
    89  	}
    90  
    91  	if len(f.Annotations) != 2 {
    92  		t.Fatalf("Unexpected annotations")
    93  	}
    94  
    95  	if want, got := "extravalue", f.Annotations["extrakey"]; want != got {
    96  		t.Errorf("Want %q, but got %q", want, got)
    97  	}
    98  
    99  	if want, got := "anothervalue", f.Annotations["anotherkey"]; want != got {
   100  		t.Errorf("Want %q, but got %q", want, got)
   101  	}
   102  
   103  	kk := []string{"frobnitz", "sprocket", "dodad"}
   104  	for i, k := range f.Keywords {
   105  		if kk[i] != k {
   106  			t.Errorf("Expected %q, got %q", kk[i], k)
   107  		}
   108  	}
   109  }
   110  
   111  func TestIsChartDir(t *testing.T) {
   112  	validChartDir, err := IsChartDir("testdata/frobnitz")
   113  	if !validChartDir {
   114  		t.Errorf("unexpected error while reading chart-directory: (%v)", err)
   115  		return
   116  	}
   117  	validChartDir, err = IsChartDir("testdata")
   118  	if validChartDir || err == nil {
   119  		t.Errorf("expected error but did not get any")
   120  		return
   121  	}
   122  }