mirror of
https://github.com/helm/helm.git
synced 2026-04-26 00:27:36 -04:00
ref(version): catch some edge cases
- strip GoVersion from `helm version` test output - catch some edge cases when GitCommit is unset or less than 7 characters - add a test case for `helm version --short` Signed-off-by: Matthew Fisher <matt.fisher@microsoft.com>
This commit is contained in:
parent
7d3693bd56
commit
a24915a079
5 changed files with 18 additions and 3 deletions
1
cmd/helm/testdata/output/version-short.txt
vendored
Normal file
1
cmd/helm/testdata/output/version-short.txt
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
v3.0+unreleased
|
||||
2
cmd/helm/testdata/output/version.txt
vendored
2
cmd/helm/testdata/output/version.txt
vendored
|
|
@ -1 +1 @@
|
|||
version.BuildInfo{Version:"v3.0+unreleased", GitCommit:"", GitTreeState:"", GoVersion:"go1.12.5"}
|
||||
version.BuildInfo{Version:"v3.0+unreleased", GitCommit:"", GitTreeState:"", GoVersion:""}
|
||||
|
|
|
|||
|
|
@ -80,7 +80,10 @@ func (o *versionOptions) run(out io.Writer) error {
|
|||
func formatVersion(short bool) string {
|
||||
v := version.Get()
|
||||
if short {
|
||||
return fmt.Sprintf("%s+g%s", v.Version, v.GitCommit[:7])
|
||||
if len(v.GitCommit) >= 7 {
|
||||
return fmt.Sprintf("%s+g%s", v.Version, v.GitCommit[:7])
|
||||
}
|
||||
return version.GetVersion()
|
||||
}
|
||||
return fmt.Sprintf("%#v", v)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,10 @@ func TestVersion(t *testing.T) {
|
|||
name: "default",
|
||||
cmd: "version",
|
||||
golden: "output/version.txt",
|
||||
}, {
|
||||
name: "short",
|
||||
cmd: "version --short",
|
||||
golden: "output/version-short.txt",
|
||||
}, {
|
||||
name: "template",
|
||||
cmd: "version --template='Version: {{.Version}}'",
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
package version // import "helm.sh/helm/internal/version"
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"runtime"
|
||||
|
||||
hversion "helm.sh/helm/pkg/version"
|
||||
|
|
@ -50,10 +51,16 @@ func GetVersion() string {
|
|||
|
||||
// Get returns build info
|
||||
func Get() hversion.BuildInfo {
|
||||
return hversion.BuildInfo{
|
||||
v := hversion.BuildInfo{
|
||||
Version: GetVersion(),
|
||||
GitCommit: gitCommit,
|
||||
GitTreeState: gitTreeState,
|
||||
GoVersion: runtime.Version(),
|
||||
}
|
||||
|
||||
// HACK(bacongobbler): strip out GoVersion during a test run for consistent test output
|
||||
if flag.Lookup("test.v") != nil {
|
||||
v.GoVersion = ""
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue