forked from kubescape/kubescape
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubescape#1481 from mohaidoss/unknown-version-fix
Fix for Empty Build Number in cmd Version
- Loading branch information
Showing
2 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package version | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"testing" | ||
|
||
"github.com/kubescape/kubescape/v3/core/cautils" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetVersionCmd(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
buildNumber string | ||
want string | ||
}{ | ||
{ | ||
name: "Undefined Build Number", | ||
buildNumber: "", | ||
want: "Your current version is: unknown\n", | ||
}, | ||
{ | ||
name: "Defined Build Number: v3.0.1", | ||
buildNumber: "v3.0.1", | ||
want: "Your current version is: v3.0.1\n", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
cautils.BuildNumber = tt.buildNumber | ||
|
||
if cmd := GetVersionCmd(); cmd != nil { | ||
buf := bytes.NewBufferString("") | ||
cmd.SetOut(buf) | ||
cmd.Execute() | ||
out, err := io.ReadAll(buf) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
assert.Equal(t, tt.want, string(out)) | ||
} | ||
}) | ||
} | ||
} |