github.com/appscode/helm@v3.0.0-alpha.1+incompatible/pkg/chartutil/create_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 "io/ioutil" 21 "os" 22 "path/filepath" 23 "strings" 24 "testing" 25 26 "helm.sh/helm/pkg/chart" 27 "helm.sh/helm/pkg/chart/loader" 28 ) 29 30 func TestCreate(t *testing.T) { 31 tdir, err := ioutil.TempDir("", "helm-") 32 if err != nil { 33 t.Fatal(err) 34 } 35 defer os.RemoveAll(tdir) 36 37 c, err := Create("foo", tdir) 38 if err != nil { 39 t.Fatal(err) 40 } 41 42 dir := filepath.Join(tdir, "foo") 43 44 mychart, err := loader.LoadDir(c) 45 if err != nil { 46 t.Fatalf("Failed to load newly created chart %q: %s", c, err) 47 } 48 49 if mychart.Name() != "foo" { 50 t.Errorf("Expected name to be 'foo', got %q", mychart.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{ 87 APIVersion: chart.APIVersionV1, 88 Name: "foo", 89 Version: "0.1.0", 90 } 91 srcdir := "./testdata/mariner" 92 93 if err := CreateFrom(cf, tdir, srcdir); err != nil { 94 t.Fatal(err) 95 } 96 97 dir := filepath.Join(tdir, "foo") 98 99 c := filepath.Join(tdir, cf.Name) 100 mychart, err := loader.LoadDir(c) 101 if err != nil { 102 t.Fatalf("Failed to load newly created chart %q: %s", c, err) 103 } 104 105 if mychart.Name() != "foo" { 106 t.Errorf("Expected name to be 'foo', got %q", mychart.Name()) 107 } 108 109 for _, d := range []string{TemplatesDir, ChartsDir} { 110 if fi, err := os.Stat(filepath.Join(dir, d)); err != nil { 111 t.Errorf("Expected %s dir: %s", d, err) 112 } else if !fi.IsDir() { 113 t.Errorf("Expected %s to be a directory.", d) 114 } 115 } 116 117 for _, f := range []string{ChartfileName, ValuesfileName} { 118 if fi, err := os.Stat(filepath.Join(dir, f)); err != nil { 119 t.Errorf("Expected %s file: %s", f, err) 120 } else if fi.IsDir() { 121 t.Errorf("Expected %s to be a file.", f) 122 } 123 } 124 125 for _, f := range []string{"placeholder.tpl"} { 126 if fi, err := os.Stat(filepath.Join(dir, TemplatesDir, f)); err != nil { 127 t.Errorf("Expected %s file: %s", f, err) 128 } else if fi.IsDir() { 129 t.Errorf("Expected %s to be a file.", f) 130 } 131 } 132 133 // Ensure we replace `<CHARTNAME>` 134 if strings.Contains(string(mychart.RawValues), "<CHARTNAME>") { 135 t.Errorf("Did not expect %s to be present in %s", "<CHARTNAME>", string(mychart.RawValues)) 136 } 137 }