github.com/cloudposse/helm@v2.2.3+incompatible/pkg/chartutil/create_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 "path/filepath" 23 "testing" 24 25 "k8s.io/helm/pkg/proto/hapi/chart" 26 ) 27 28 func TestCreate(t *testing.T) { 29 tdir, err := ioutil.TempDir("", "helm-") 30 if err != nil { 31 t.Fatal(err) 32 } 33 defer os.RemoveAll(tdir) 34 35 cf := &chart.Metadata{Name: "foo"} 36 37 c, err := Create(cf, tdir) 38 if err != nil { 39 t.Fatal(err) 40 } 41 42 dir := filepath.Join(tdir, "foo") 43 44 mychart, err := LoadDir(c) 45 if err != nil { 46 t.Fatalf("Failed to load newly created chart %q: %s", c, err) 47 } 48 49 if mychart.Metadata.Name != "foo" { 50 t.Errorf("Expected name to be 'foo', got %q", mychart.Metadata.Name) 51 } 52 53 for _, d := range []string{TemplatesDir, ChartsDir} { 54 if fi, err := os.Stat(filepath.Join(dir, d)); err != nil { 55 t.Errorf("Expected %s dir: %s", d, err) 56 } else if !fi.IsDir() { 57 t.Errorf("Expected %s to be a directory.", d) 58 } 59 } 60 61 for _, f := range []string{ChartfileName, ValuesfileName, IgnorefileName} { 62 if fi, err := os.Stat(filepath.Join(dir, f)); err != nil { 63 t.Errorf("Expected %s file: %s", f, err) 64 } else if fi.IsDir() { 65 t.Errorf("Expected %s to be a file.", f) 66 } 67 } 68 69 for _, f := range []string{NotesName, DeploymentName, ServiceName, HelpersName} { 70 if fi, err := os.Stat(filepath.Join(dir, TemplatesDir, f)); err != nil { 71 t.Errorf("Expected %s file: %s", f, err) 72 } else if fi.IsDir() { 73 t.Errorf("Expected %s to be a file.", f) 74 } 75 } 76 77 } 78 79 func TestCreateFrom(t *testing.T) { 80 tdir, err := ioutil.TempDir("", "helm-") 81 if err != nil { 82 t.Fatal(err) 83 } 84 defer os.RemoveAll(tdir) 85 86 cf := &chart.Metadata{Name: "foo"} 87 srcdir := "./testdata/mariner" 88 89 if err := CreateFrom(cf, tdir, srcdir); err != nil { 90 t.Fatal(err) 91 } 92 93 dir := filepath.Join(tdir, "foo") 94 95 c := filepath.Join(tdir, cf.Name) 96 mychart, err := LoadDir(c) 97 if err != nil { 98 t.Fatalf("Failed to load newly created chart %q: %s", c, err) 99 } 100 101 if mychart.Metadata.Name != "foo" { 102 t.Errorf("Expected name to be 'foo', got %q", mychart.Metadata.Name) 103 } 104 105 for _, d := range []string{TemplatesDir, ChartsDir} { 106 if fi, err := os.Stat(filepath.Join(dir, d)); err != nil { 107 t.Errorf("Expected %s dir: %s", d, err) 108 } else if !fi.IsDir() { 109 t.Errorf("Expected %s to be a directory.", d) 110 } 111 } 112 113 for _, f := range []string{ChartfileName, ValuesfileName, "requirements.yaml"} { 114 if fi, err := os.Stat(filepath.Join(dir, f)); err != nil { 115 t.Errorf("Expected %s file: %s", f, err) 116 } else if fi.IsDir() { 117 t.Errorf("Expected %s to be a file.", f) 118 } 119 } 120 121 for _, f := range []string{"placeholder.tpl"} { 122 if fi, err := os.Stat(filepath.Join(dir, TemplatesDir, f)); err != nil { 123 t.Errorf("Expected %s file: %s", f, err) 124 } else if fi.IsDir() { 125 t.Errorf("Expected %s to be a file.", f) 126 } 127 } 128 }