Skip to content

Commit 28eee84

Browse files
committed
add another test
Signed-off-by: Troy Connor <[email protected]>
1 parent ac24b76 commit 28eee84

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

tools/setup-envtest/workflows/workflows.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,14 @@ type Version struct {
9696

9797
// Do executes the workflow.
9898
func (v Version) Do(env *envp.Env) {
99+
version := "(unknown)"
99100
if v.BinaryVersion == "" {
100101
info, ok := debug.ReadBuildInfo()
101-
if !ok || info == nil || info.Main.Version == "" {
102+
if (ok && info != nil) || info.Main.Version != "" {
102103
// binary has not been built with module support or doesn't contain a version.
103-
fmt.Fprintf(env.Out, "setup-envtest version: %s\n", "(unknown)")
104-
return
104+
version = fmt.Sprintf("%s", info.Main.Version)
105105
}
106-
fmt.Fprintf(env.Out, "setup-envtest version: %s\n", info.Main.Version)
107-
return
106+
v.BinaryVersion = version
108107
}
109108
fmt.Fprintf(env.Out, "setup-envtest version: %s\n", v.BinaryVersion)
110109
}

tools/setup-envtest/workflows/workflows_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"io/fs"
1010
"path/filepath"
11+
"runtime/debug"
1112
"sort"
1213
"strings"
1314

@@ -447,11 +448,20 @@ var _ = Describe("Workflows", func() {
447448
Describe("version", func() {
448449
It("should print out the version based on the Binary Version", func() {
449450
v := wf.Version{
450-
BinaryVersion: "release-0.18",
451+
BinaryVersion: "v0.18.2",
451452
}
452453
v.Do(env)
453454
Expect(out.String()).ToNot(BeEmpty())
454-
Expect(out.String()).To(Equal("setup-envtest version: release-0.18\n"))
455+
Expect(out.String()).To(Equal("setup-envtest version: v0.18.2\n"))
456+
})
457+
458+
It("should print out the version if the RELEASE_TAG is empty", func() {
459+
v := wf.Version{}
460+
v.Do(env)
461+
info, ok := debug.ReadBuildInfo()
462+
Expect(ok).To(BeTrue())
463+
Expect(out.String()).ToNot(BeEmpty())
464+
Expect(out.String()).To(Equal(fmt.Sprintf("setup-envtest version: %s\n", info.Main.Version)))
455465
})
456466
})
457467

0 commit comments

Comments
 (0)