Skip to content

Commit

Permalink
Adds test around VersionInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Gowiem committed Jun 20, 2020
1 parent 15baca4 commit b41f36e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
16 changes: 10 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ type VersionInfo struct {

var vInfo VersionInfo

func (v VersionInfo) String() string {
return fmt.Sprintf(
"ecsrun version info\nVersion: %s\nCommit: %s\nDate Built: %s\nBuilt By: %s\n",
v.Version,
v.Commit,
v.Date,
v.BuiltBy)
}

var cfgFile string

var log = logrus.New()
Expand Down Expand Up @@ -138,12 +147,7 @@ func initVerbose() {

func initVersion() {
if viper.GetBool("version") {
fmt.Printf(
"ecsrun version info\nVersion: %s\nCommit: %s\nDate Built: %s\nBuilt By: %s\n",
vInfo.Version,
vInfo.Commit,
vInfo.Date,
vInfo.BuiltBy)
fmt.Print(vInfo.String())
os.Exit(0)
}
}
Expand Down
23 changes: 22 additions & 1 deletion cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestExecute(t *testing.T) {
os.Setenv("ECSRUN_TASK", "task")
os.Setenv("ECSRUN_VERBOSE", "true")

Execute(newEcsClientFake)
Execute(newEcsClientFake, VersionInfo{})

var sesh = viper.Get("session")
cred, _ := sesh.(*session.Session).Config.Credentials.Get()
Expand All @@ -67,6 +67,27 @@ func TestExecute(t *testing.T) {
teardown()
}

func TestVersion(t *testing.T) {
setup()
assert := assert.New(t)

vInfo := VersionInfo{
Version: "0.1.0",
Commit: "238958943",
Date: "06/19/20",
BuiltBy: "MDG",
}

result := vInfo.String()

assert.Contains(result, "0.1.0")
assert.Contains(result, "238958943")
assert.Contains(result, "06/19/20")
assert.Contains(result, "MDG")

teardown()
}

func TestInitAws(t *testing.T) {
assert := assert.New(t)
setup()
Expand Down

0 comments on commit b41f36e

Please sign in to comment.