Skip to content

Commit

Permalink
feat(helm): add newline to fetch --verify output
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaughn Dice committed Dec 13, 2016
1 parent 0d436e5 commit 4dd77e7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cmd/helm/fetch.go
Expand Up @@ -124,7 +124,7 @@ func (f *fetchCmd) run() error {
}

if f.verify {
fmt.Fprintf(f.out, "Verification: %v", v)
fmt.Fprintf(f.out, "Verification: %v\n", v)
}

// After verification, untar the chart into the requested directory.
Expand Down
48 changes: 31 additions & 17 deletions cmd/helm/fetch_test.go
Expand Up @@ -18,8 +18,10 @@ package main

import (
"bytes"
"fmt"
"os"
"path/filepath"
"regexp"
"testing"

"k8s.io/helm/pkg/repo/repotest"
Expand All @@ -39,13 +41,14 @@ func TestFetchCmd(t *testing.T) {

// all flags will get "--home=TMDIR -d outdir" appended.
tests := []struct {
name string
chart string
flags []string
fail bool
failExpect string
expectFile string
expectDir bool
name string
chart string
flags []string
fail bool
failExpect string
expectFile string
expectDir bool
expectVerify bool
}{
{
name: "Basic chart fetch",
Expand All @@ -72,10 +75,11 @@ func TestFetchCmd(t *testing.T) {
fail: true,
},
{
name: "Fetch and verify",
chart: "test/signtest",
flags: []string{"--verify", "--keyring", "testdata/helm-test-key.pub"},
expectFile: "./signtest-0.1.0.tgz",
name: "Fetch and verify",
chart: "test/signtest",
flags: []string{"--verify", "--keyring", "testdata/helm-test-key.pub"},
expectFile: "./signtest-0.1.0.tgz",
expectVerify: true,
},
{
name: "Fetch and fail verify",
Expand All @@ -87,16 +91,17 @@ func TestFetchCmd(t *testing.T) {
{
name: "Fetch and untar",
chart: "test/signtest",
flags: []string{"--verify", "--keyring", "testdata/helm-test-key.pub", "--untar", "--untardir", "signtest"},
flags: []string{"--untar", "--untardir", "signtest"},
expectFile: "./signtest",
expectDir: true,
},
{
name: "Fetch, verify, untar",
chart: "test/signtest",
flags: []string{"--verify", "--keyring", "testdata/helm-test-key.pub", "--untar", "--untardir", "signtest"},
expectFile: "./signtest",
expectDir: true,
name: "Fetch, verify, untar",
chart: "test/signtest",
flags: []string{"--verify", "--keyring", "testdata/helm-test-key.pub", "--untar", "--untardir", "signtest"},
expectFile: "./signtest",
expectDir: true,
expectVerify: true,
},
}

Expand Down Expand Up @@ -126,6 +131,15 @@ func TestFetchCmd(t *testing.T) {
t.Errorf("%q reported error: %s", tt.name, err)
continue
}
if tt.expectVerify {
pointerAddressPattern := "0[xX][A-Fa-f0-9]+"
sha256Pattern := "[A-Fa-f0-9]{64}"
verificationRegex := regexp.MustCompile(
fmt.Sprintf("Verification: &{%s sha256:%s signtest-0.1.0.tgz}\n", pointerAddressPattern, sha256Pattern))
if !verificationRegex.MatchString(buf.String()) {
t.Errorf("%q: expected match for regex %s, got %s", tt.name, verificationRegex, buf.String())
}
}

ef := filepath.Join(outdir, tt.expectFile)
fi, err := os.Stat(ef)
Expand Down

0 comments on commit 4dd77e7

Please sign in to comment.