github.com/danielqsj/helm@v2.0.0-alpha.4.0.20160908204436-976e0ba5199b+incompatible/pkg/chartutil/load_test.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors All rights reserved. 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 "k8s.io/helm/pkg/proto/hapi/chart" 23 ) 24 25 func TestLoadDir(t *testing.T) { 26 c, err := Load("testdata/frobnitz") 27 if err != nil { 28 t.Fatalf("Failed to load testdata: %s", err) 29 } 30 verifyFrobnitz(t, c) 31 verifyChart(t, c) 32 } 33 34 func TestLoadFile(t *testing.T) { 35 c, err := Load("testdata/frobnitz-1.2.3.tgz") 36 if err != nil { 37 t.Fatalf("Failed to load testdata: %s", err) 38 } 39 verifyFrobnitz(t, c) 40 verifyChart(t, c) 41 } 42 43 func verifyChart(t *testing.T, c *chart.Chart) { 44 if c.Metadata.Name == "" { 45 t.Fatalf("No chart metadata found on %v", c) 46 } 47 t.Logf("Verifying chart %s", c.Metadata.Name) 48 if len(c.Templates) != 1 { 49 t.Errorf("Expected 1 template, got %d", len(c.Templates)) 50 } 51 52 numfiles := 6 53 if len(c.Files) != numfiles { 54 t.Errorf("Expected %d extra files, got %d", numfiles, len(c.Files)) 55 for _, n := range c.Files { 56 t.Logf("\t%s", n.TypeUrl) 57 } 58 } 59 60 if len(c.Dependencies) != 2 { 61 t.Errorf("Expected 2 dependencies, got %d (%v)", len(c.Dependencies), c.Dependencies) 62 for _, d := range c.Dependencies { 63 t.Logf("\tSubchart: %s\n", d.Metadata.Name) 64 } 65 } 66 67 expect := map[string]map[string]string{ 68 "alpine": { 69 "version": "0.1.0", 70 }, 71 "mariner": { 72 "version": "4.3.2", 73 }, 74 } 75 76 for _, dep := range c.Dependencies { 77 if dep.Metadata == nil { 78 t.Fatalf("expected metadata on dependency: %v", dep) 79 } 80 exp, ok := expect[dep.Metadata.Name] 81 if !ok { 82 t.Fatalf("Unknown dependency %s", dep.Metadata.Name) 83 } 84 if exp["version"] != dep.Metadata.Version { 85 t.Errorf("Expected %s version %s, got %s", dep.Metadata.Name, exp["version"], dep.Metadata.Version) 86 } 87 } 88 89 } 90 91 func verifyFrobnitz(t *testing.T, c *chart.Chart) { 92 verifyChartfile(t, c.Metadata) 93 94 if len(c.Templates) != 1 { 95 t.Fatalf("Expected 1 template, got %d", len(c.Templates)) 96 } 97 98 if c.Templates[0].Name != "templates/template.tpl" { 99 t.Errorf("Unexpected template: %s", c.Templates[0].Name) 100 } 101 102 if len(c.Templates[0].Data) == 0 { 103 t.Error("No template data.") 104 } 105 }