From 281a5f49c4cb6dd3fda3b65124fe3e9ae3e43e78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Sun, 10 Feb 2019 11:36:24 -0500 Subject: [PATCH] Refactor chart test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- pkg/chartutil/create_test.go | 58 ++++++++++++++---------------------- 1 file changed, 23 insertions(+), 35 deletions(-) diff --git a/pkg/chartutil/create_test.go b/pkg/chartutil/create_test.go index a0ddf8fa2..114577743 100644 --- a/pkg/chartutil/create_test.go +++ b/pkg/chartutil/create_test.go @@ -26,6 +26,22 @@ import ( "k8s.io/helm/pkg/proto/hapi/chart" ) +func checkDir(t *testing.T, d string) { + if fi, err := os.Stat(d); err != nil { + t.Errorf("Expected %s dir: %s", d, err) + } else if !fi.IsDir() { + t.Errorf("Expected %s to be a directory.", d) + } +} + +func checkFile(t *testing.T, f string) { + if fi, err := os.Stat(f); err != nil { + t.Errorf("Expected %s file: %s", filepath.Base(f), err) + } else if fi.IsDir() { + t.Errorf("Expected %s to be a file.", filepath.Base(f)) + } +} + func TestCreate(t *testing.T) { tdir, err := ioutil.TempDir("", "helm-") if err != nil { @@ -52,35 +68,19 @@ func TestCreate(t *testing.T) { } for _, d := range []string{TemplatesDir, ChartsDir} { - if fi, err := os.Stat(filepath.Join(dir, d)); err != nil { - t.Errorf("Expected %s dir: %s", d, err) - } else if !fi.IsDir() { - t.Errorf("Expected %s to be a directory.", d) - } + checkDir(t, filepath.Join(dir, d)) } for _, f := range []string{ChartfileName, ValuesfileName, IgnorefileName} { - if fi, err := os.Stat(filepath.Join(dir, f)); err != nil { - t.Errorf("Expected %s file: %s", f, err) - } else if fi.IsDir() { - t.Errorf("Expected %s to be a file.", f) - } + checkFile(t, filepath.Join(dir, f)) } for _, f := range []string{NotesName, DeploymentName, ServiceName, HelpersName} { - if fi, err := os.Stat(filepath.Join(dir, TemplatesDir, f)); err != nil { - t.Errorf("Expected %s file: %s", f, err) - } else if fi.IsDir() { - t.Errorf("Expected %s to be a file.", f) - } + checkFile(t, filepath.Join(dir, TemplatesDir, f)) } for _, f := range []string{TestConnectionName} { - if fi, err := os.Stat(filepath.Join(dir, TemplatesTestsDir, f)); err != nil { - t.Errorf("Expected %s file: %s", f, err) - } else if fi.IsDir() { - t.Errorf("Expected %s to be a file.", f) - } + checkFile(t, filepath.Join(dir, TemplatesTestsDir, f)) } } @@ -112,27 +112,15 @@ func TestCreateFrom(t *testing.T) { } for _, d := range []string{TemplatesDir, ChartsDir} { - if fi, err := os.Stat(filepath.Join(dir, d)); err != nil { - t.Errorf("Expected %s dir: %s", d, err) - } else if !fi.IsDir() { - t.Errorf("Expected %s to be a directory.", d) - } + checkDir(t, filepath.Join(dir, d)) } for _, f := range []string{ChartfileName, ValuesfileName, "requirements.yaml"} { - if fi, err := os.Stat(filepath.Join(dir, f)); err != nil { - t.Errorf("Expected %s file: %s", f, err) - } else if fi.IsDir() { - t.Errorf("Expected %s to be a file.", f) - } + checkFile(t, filepath.Join(dir, f)) } for _, f := range []string{"placeholder.tpl"} { - if fi, err := os.Stat(filepath.Join(dir, TemplatesDir, f)); err != nil { - t.Errorf("Expected %s file: %s", f, err) - } else if fi.IsDir() { - t.Errorf("Expected %s to be a file.", f) - } + checkFile(t, filepath.Join(dir, TemplatesDir, f)) } // Ensure we replace ``