mirror of https://github.com/knative/client.git
kn version command to list supported serving versions and APIs (#370)
Fixes #369
- Replace `Dependencies:` with `Support:`
- Add list of supported Serving versions kn can work with
- Add list of supported Serving APIs kn can work with
```
✗ ./kn version
Version: v20190816-local-e36089f-dirty
Build Date: 2019-08-16 13:08:26
Git Revision: e36089f
Support:
- Serving: v0.8.0 v0.7.1
- API(s): v1alpha1
```
This commit is contained in:
parent
e36089f260
commit
dccaf36611
|
|
@ -46,6 +46,9 @@
|
||||||
| Support traffic splitting and tagging targets
|
| Support traffic splitting and tagging targets
|
||||||
| https://github.com/knative/client/pull/345[#345]
|
| https://github.com/knative/client/pull/345[#345]
|
||||||
|
|
||||||
|
| 🎁
|
||||||
|
| kn version command shows supported Serving and API versions
|
||||||
|
| https://github.com/knative/client/pull/370[#370]
|
||||||
|
|
||||||
|===
|
|===
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
@ -25,6 +26,18 @@ var BuildDate string
|
||||||
var GitRevision string
|
var GitRevision string
|
||||||
var ServingVersion string
|
var ServingVersion string
|
||||||
|
|
||||||
|
// VersionsAPIs hold the list of supported versions and APIs for component kn can work with
|
||||||
|
type VersionsAPIs struct {
|
||||||
|
Versions, APIs []string
|
||||||
|
}
|
||||||
|
|
||||||
|
// update this var as we increase the serving version in go.mod
|
||||||
|
var knServingDep = "v0.8.0"
|
||||||
|
var supportMatrix = map[string]*VersionsAPIs{
|
||||||
|
knServingDep: {[]string{"v0.8.0", "v0.7.1"}, []string{"v1alpha1"}},
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewVersionCommand implements 'kn version' command
|
||||||
func NewVersionCommand(p *KnParams) *cobra.Command {
|
func NewVersionCommand(p *KnParams) *cobra.Command {
|
||||||
versionCmd := &cobra.Command{
|
versionCmd := &cobra.Command{
|
||||||
Use: "version",
|
Use: "version",
|
||||||
|
|
@ -33,8 +46,15 @@ func NewVersionCommand(p *KnParams) *cobra.Command {
|
||||||
fmt.Printf("Version: %s\n", Version)
|
fmt.Printf("Version: %s\n", Version)
|
||||||
fmt.Printf("Build Date: %s\n", BuildDate)
|
fmt.Printf("Build Date: %s\n", BuildDate)
|
||||||
fmt.Printf("Git Revision: %s\n", GitRevision)
|
fmt.Printf("Git Revision: %s\n", GitRevision)
|
||||||
fmt.Printf("Dependencies:\n")
|
fmt.Printf("Support:\n")
|
||||||
fmt.Printf("- serving: %s\n", ServingVersion)
|
if m, ok := supportMatrix[ServingVersion]; ok {
|
||||||
|
fmt.Printf("- Serving: %s\n", strings.Join(m.Versions, " "))
|
||||||
|
fmt.Printf("- API(s): %s\n", strings.Join(m.APIs, " "))
|
||||||
|
} else {
|
||||||
|
// ensure the go build works when we update,
|
||||||
|
// but version command tests fails to prevent shipping
|
||||||
|
fmt.Printf("- Serving: %s\n", ServingVersion)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,21 +27,21 @@ type versionOutput struct {
|
||||||
Version string
|
Version string
|
||||||
BuildDate string
|
BuildDate string
|
||||||
GitRevision string
|
GitRevision string
|
||||||
ServingVersion string
|
VersionsAPIs *VersionsAPIs
|
||||||
}
|
}
|
||||||
|
|
||||||
var versionOutputTemplate = `Version: {{.Version}}
|
var versionOutputTemplate = `Version: {{.Version}}
|
||||||
Build Date: {{.BuildDate}}
|
Build Date: {{.BuildDate}}
|
||||||
Git Revision: {{.GitRevision}}
|
Git Revision: {{.GitRevision}}
|
||||||
Dependencies:
|
Support:
|
||||||
- serving: {{.ServingVersion}}
|
- Serving: {{index .VersionsAPIs.Versions 0}} {{index .VersionsAPIs.Versions 1}}
|
||||||
|
- API(s): {{index .VersionsAPIs.APIs 0}}
|
||||||
`
|
`
|
||||||
|
|
||||||
const (
|
const (
|
||||||
fakeVersion = "fake-version"
|
fakeVersion = "fake-version"
|
||||||
fakeBuildDate = "fake-build-date"
|
fakeBuildDate = "fake-build-date"
|
||||||
fakeGitRevision = "fake-git-revision"
|
fakeGitRevision = "fake-git-revision"
|
||||||
fakeServingVersion = "fake-serving-version"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestVersion(t *testing.T) {
|
func TestVersion(t *testing.T) {
|
||||||
|
|
@ -55,14 +55,14 @@ func TestVersion(t *testing.T) {
|
||||||
Version = fakeVersion
|
Version = fakeVersion
|
||||||
BuildDate = fakeBuildDate
|
BuildDate = fakeBuildDate
|
||||||
GitRevision = fakeGitRevision
|
GitRevision = fakeGitRevision
|
||||||
ServingVersion = fakeServingVersion
|
ServingVersion = knServingDep
|
||||||
|
|
||||||
expectedVersionOutput = genVersionOuput(t, versionOutputTemplate,
|
expectedVersionOutput = genVersionOuput(t, versionOutputTemplate,
|
||||||
versionOutput{
|
versionOutput{
|
||||||
Version: fakeVersion,
|
fakeVersion,
|
||||||
BuildDate: fakeBuildDate,
|
fakeBuildDate,
|
||||||
GitRevision: fakeGitRevision,
|
fakeGitRevision,
|
||||||
ServingVersion: fakeServingVersion})
|
supportMatrix[ServingVersion]})
|
||||||
|
|
||||||
knParams = &KnParams{}
|
knParams = &KnParams{}
|
||||||
versionCmd = NewVersionCommand(knParams)
|
versionCmd = NewVersionCommand(knParams)
|
||||||
|
|
@ -78,26 +78,27 @@ func TestVersion(t *testing.T) {
|
||||||
assert.Assert(t, versionCmd.RunE != nil)
|
assert.Assert(t, versionCmd.RunE != nil)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("prints version, build date, git revision, and serving version string", func(t *testing.T) {
|
t.Run("prints version, build date, git revision, supported serving version and APIs", func(t *testing.T) {
|
||||||
setup()
|
setup()
|
||||||
CaptureStdout(t)
|
CaptureStdout(t)
|
||||||
defer ReleaseStdout(t)
|
defer ReleaseStdout(t)
|
||||||
|
|
||||||
err := versionCmd.RunE(nil, []string{})
|
err := versionCmd.RunE(nil, []string{})
|
||||||
assert.Assert(t, err == nil)
|
assert.NilError(t, err)
|
||||||
assert.Equal(t, ReadStdout(t), expectedVersionOutput)
|
assert.Equal(t, ReadStdout(t), expectedVersionOutput)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private
|
// Private
|
||||||
|
|
||||||
func genVersionOuput(t *testing.T, templ string, vOutput versionOutput) string {
|
func genVersionOuput(t *testing.T, templ string, vOutput versionOutput) string {
|
||||||
tmpl, err := template.New("versionOutput").Parse(versionOutputTemplate)
|
tmpl, err := template.New("versionOutput").Parse(versionOutputTemplate)
|
||||||
assert.Assert(t, err == nil)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
buf := bytes.Buffer{}
|
buf := bytes.Buffer{}
|
||||||
err = tmpl.Execute(&buf, vOutput)
|
err = tmpl.Execute(&buf, vOutput)
|
||||||
assert.Assert(t, err == nil)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue