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