Skip to content

Commit

Permalink
chore: improve func version verbose mode to display image referenced …
Browse files Browse the repository at this point in the history
…by func (#1431)
  • Loading branch information
jrangelramos authored Nov 16, 2022
1 parent 0073106 commit 1ca6625
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
8 changes: 7 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"knative.dev/func/cmd/templates"
"knative.dev/func/config"
"knative.dev/func/k8s"

"github.com/ory/viper"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -383,7 +384,12 @@ func (v Version) StringVerbose() string {
if date == "" {
date = time.Now().Format(time.RFC3339)
}
return fmt.Sprintf("%s-%s-%s", vers, hash, date)
funcVersion := fmt.Sprintf("%s-%s-%s", vers, hash, date)
return fmt.Sprintf("Version: %s\n"+
"SocatImage: %s\n"+
"TarImage: %s", funcVersion,
k8s.SocatImage,
k8s.TarImage)
}

// surveySelectDefault returns 'value' if defined and exists in 'options'.
Expand Down
36 changes: 22 additions & 14 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,24 +214,28 @@ func TestRoot_CommandNameParameterized(t *testing.T) {

func TestVerbose(t *testing.T) {
tests := []struct {
name string
args []string
want string
name string
args []string
want string
wantLF int
}{
{
name: "verbose as version's flag",
args: []string{"version", "-v"},
want: "v0.42.0-cafe-1970-01-01\n",
name: "verbose as version's flag",
args: []string{"version", "-v"},
want: "Version: v0.42.0-cafe-1970-01-01",
wantLF: 3,
},
{
name: "no verbose",
args: []string{"version"},
want: "v0.42.0\n",
name: "no verbose",
args: []string{"version"},
want: "v0.42.0",
wantLF: 1,
},
{
name: "verbose as root's flag",
args: []string{"--verbose", "version"},
want: "v0.42.0-cafe-1970-01-01\n",
name: "verbose as root's flag",
args: []string{"--verbose", "version"},
want: "Version: v0.42.0-cafe-1970-01-01",
wantLF: 3,
},
}
for _, tt := range tests {
Expand All @@ -254,8 +258,12 @@ func TestVerbose(t *testing.T) {
t.Fatal(err)
}

if out.String() != tt.want {
t.Errorf("expected output: %q but got: %q", tt.want, out.String())
outLines := strings.Split(out.String(), "\n")
if len(outLines)-1 != tt.wantLF {
t.Errorf("expected output with %v line breaks but got %v:", tt.wantLF, len(outLines)-1)
}
if outLines[0] != tt.want {
t.Errorf("expected output: %q but got: %q", tt.want, outLines[0])
}
})
}
Expand Down

0 comments on commit 1ca6625

Please sign in to comment.