github.com/migueleliasweb/helm@v2.6.1+incompatible/pkg/chartutil/save_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 "io/ioutil" 21 "os" 22 "strings" 23 "testing" 24 25 "k8s.io/helm/pkg/proto/hapi/chart" 26 ) 27 28 func TestSave(t *testing.T) { 29 tmp, err := ioutil.TempDir("", "helm-") 30 if err != nil { 31 t.Fatal(err) 32 } 33 defer os.RemoveAll(tmp) 34 35 c := &chart.Chart{ 36 Metadata: &chart.Metadata{ 37 Name: "ahab", 38 Version: "1.2.3.4", 39 }, 40 Values: &chart.Config{ 41 Raw: "ship: Pequod", 42 }, 43 } 44 45 where, err := Save(c, tmp) 46 if err != nil { 47 t.Fatalf("Failed to save: %s", err) 48 } 49 if !strings.HasPrefix(where, tmp) { 50 t.Fatalf("Expected %q to start with %q", where, tmp) 51 } 52 if !strings.HasSuffix(where, ".tgz") { 53 t.Fatalf("Expected %q to end with .tgz", where) 54 } 55 56 c2, err := LoadFile(where) 57 if err != nil { 58 t.Fatal(err) 59 } 60 61 if c2.Metadata.Name != c.Metadata.Name { 62 t.Fatalf("Expected chart archive to have %q, got %q", c.Metadata.Name, c2.Metadata.Name) 63 } 64 if c2.Values.Raw != c.Values.Raw { 65 t.Fatal("Values data did not match") 66 } 67 } 68 69 func TestSaveDir(t *testing.T) { 70 tmp, err := ioutil.TempDir("", "helm-") 71 if err != nil { 72 t.Fatal(err) 73 } 74 defer os.RemoveAll(tmp) 75 76 c := &chart.Chart{ 77 Metadata: &chart.Metadata{ 78 Name: "ahab", 79 Version: "1.2.3.4", 80 }, 81 Values: &chart.Config{ 82 Raw: "ship: Pequod", 83 }, 84 } 85 86 if err := SaveDir(c, tmp); err != nil { 87 t.Fatalf("Failed to save: %s", err) 88 } 89 90 c2, err := LoadDir(tmp + "/ahab") 91 if err != nil { 92 t.Fatal(err) 93 } 94 95 if c2.Metadata.Name != c.Metadata.Name { 96 t.Fatalf("Expected chart archive to have %q, got %q", c.Metadata.Name, c2.Metadata.Name) 97 } 98 if c2.Values.Raw != c.Values.Raw { 99 t.Fatal("Values data did not match") 100 } 101 }