fix: helm package tests

Signed-off-by: Tomas Pizarro Moreno <tpizarro@vmware.com>
pull/10609/head
Tomas Pizarro Moreno 3 years ago
parent e02aeab0e9
commit 0963617b9b

@ -16,10 +16,11 @@ limitations under the License.
package main package main
import ( import (
"bytes" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strings"
"testing" "testing"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -118,15 +119,12 @@ func TestPackage(t *testing.T) {
if err := os.MkdirAll("toot", 0777); err != nil { if err := os.MkdirAll("toot", 0777); err != nil {
t.Fatal(err) t.Fatal(err)
} }
var buf bytes.Buffer
c := newPackageCmd(&buf)
// This is an unfortunate byproduct of the tmpdir // This is an unfortunate byproduct of the tmpdir
if v, ok := tt.flags["keyring"]; ok && len(v) > 0 { if v, ok := tt.flags["keyring"]; ok && len(v) > 0 {
tt.flags["keyring"] = filepath.Join(origDir, v) tt.flags["keyring"] = filepath.Join(origDir, v)
} }
setFlags(c, tt.flags)
re := regexp.MustCompile(tt.expect) re := regexp.MustCompile(tt.expect)
adjustedArgs := make([]string, len(tt.args)) adjustedArgs := make([]string, len(tt.args))
@ -134,7 +132,16 @@ func TestPackage(t *testing.T) {
adjustedArgs[i] = filepath.Join(origDir, f) adjustedArgs[i] = filepath.Join(origDir, f)
} }
err := c.RunE(c, adjustedArgs) cmd := []string{"package"}
if len(adjustedArgs) > 0 {
cmd = append(cmd, adjustedArgs...)
}
for k, v := range tt.flags {
if v != "0" {
cmd = append(cmd, fmt.Sprintf("--%s=%s", k, v))
}
}
_, _, err = executeActionCommand(strings.Join(cmd, " "))
if err != nil { if err != nil {
if tt.err && re.MatchString(err.Error()) { if tt.err && re.MatchString(err.Error()) {
return return
@ -142,10 +149,6 @@ func TestPackage(t *testing.T) {
t.Fatalf("%q: expected error %q, got %q", tt.name, tt.expect, err) t.Fatalf("%q: expected error %q, got %q", tt.name, tt.expect, err)
} }
if !re.Match(buf.Bytes()) {
t.Errorf("%q: expected output %q, got %q", tt.name, tt.expect, buf.String())
}
if len(tt.hasfile) > 0 { if len(tt.hasfile) > 0 {
if fi, err := os.Stat(tt.hasfile); err != nil { if fi, err := os.Stat(tt.hasfile); err != nil {
t.Errorf("%q: expected file %q, got err %q", tt.name, tt.hasfile, err) t.Errorf("%q: expected file %q, got err %q", tt.name, tt.hasfile, err)
@ -168,26 +171,21 @@ func TestPackage(t *testing.T) {
func TestSetAppVersion(t *testing.T) { func TestSetAppVersion(t *testing.T) {
var ch *chart.Chart var ch *chart.Chart
expectedAppVersion := "app-version-foo" expectedAppVersion := "app-version-foo"
chartToPackage := "testdata/testcharts/alpine"
dir := ensure.TempDir(t) dir := ensure.TempDir(t)
cmd := fmt.Sprintf("package %s --destination=%s --app-version=%s", chartToPackage, dir, expectedAppVersion)
c := newPackageCmd(&bytes.Buffer{}) _, output, err := executeActionCommand(cmd)
flags := map[string]string{ if err != nil {
"destination": dir, t.Logf("Output: %s", output)
"app-version": expectedAppVersion, t.Fatal(err)
}
setFlags(c, flags)
if err := c.RunE(c, []string{"testdata/testcharts/alpine"}); err != nil {
t.Errorf("unexpected error %q", err)
} }
chartPath := filepath.Join(dir, "alpine-0.1.0.tgz") chartPath := filepath.Join(dir, "alpine-0.1.0.tgz")
if fi, err := os.Stat(chartPath); err != nil { if fi, err := os.Stat(chartPath); err != nil {
t.Errorf("expected file %q, got err %q", chartPath, err) t.Errorf("expected file %q, got err %q", chartPath, err)
} else if fi.Size() == 0 { } else if fi.Size() == 0 {
t.Errorf("file %q has zero bytes.", chartPath) t.Errorf("file %q has zero bytes.", chartPath)
} }
ch, err := loader.Load(chartPath) ch, err = loader.Load(chartPath)
if err != nil { if err != nil {
t.Fatalf("unexpected error loading packaged chart: %v", err) t.Fatalf("unexpected error loading packaged chart: %v", err)
} }

Loading…
Cancel
Save