Skip to content

Commit

Permalink
Fixes + cleans up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gowiem committed Jun 20, 2020
1 parent fac8139 commit 6a724ea
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
5 changes: 3 additions & 2 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ var InitCmd = &cobra.Command{
Use: "init",
Short: "Creates a blank `ecsrun.yml` config file in the current directory.",
Run: func(cmd *cobra.Command, args []string) {
// Reset viper as it carries over config from root. We want to build our own config.
viper.Reset()

initCmd()
},
}

func initCmd() {
// Reset viper as it carries over config from root. We want to build our own config.
viper.Reset()

config := make(map[string]interface{})
config["default"] = map[string]interface{}{
Expand Down
7 changes: 5 additions & 2 deletions cmd/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ var testFs = afero.NewMemMapFs()
func TestInitCmd(t *testing.T) {
assert := assert.New(t)

viper.SetFs(testFs)

exists, err := afero.Exists(testFs, "./ecsrun.yaml")
if err != nil {
panic(err)
}
assert.False(exists)

viper.SetFs(testFs)

initCmd()

exists, err = afero.Exists(testFs, "./ecsrun.yaml")
Expand All @@ -34,4 +34,7 @@ func TestInitCmd(t *testing.T) {
assert.True(exists)

testFs.Remove("./ecsrun.yaml")

// Set back the FS to not affect other tests
viper.SetFs(afero.NewOsFs())
}
20 changes: 10 additions & 10 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ type VersionInfo struct {
BuiltBy string
}

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",
Expand All @@ -40,11 +38,13 @@ func (v VersionInfo) String() string {
v.BuiltBy)
}

var log = logrus.New()

var fs = afero.NewOsFs()

var newEcsClient func(*RunConfig) ECSClient
var (
vInfo VersionInfo
log = logrus.New()
fs = afero.NewOsFs()
newEcsClient func(*RunConfig) ECSClient
cyan = color.New(color.FgCyan, color.Bold)
)

var rootCmd *cobra.Command = &cobra.Command{
Use: "escrun",
Expand Down Expand Up @@ -77,9 +77,7 @@ using their existing Task Definitions.`,

// If we're running with --dry-run then print the input and exit.
if viper.GetBool("dry-run") {
cyan := color.New(color.FgCyan, color.Bold)
cyan.Printf("DryRun! RunTaskInput:\n")

fmt.Println(prettyString)

os.Exit(0)
Expand All @@ -91,8 +89,9 @@ using their existing Task Definitions.`,
log.Fatal(err)
}

cyan.Printf("RunTaskOutput: \n")
prettyOut, _ := prettyjson.Marshal(output)
log.Info("RunTaskOutput: ", string(prettyOut))
fmt.Println(string(prettyOut))
},
}

Expand Down Expand Up @@ -316,6 +315,7 @@ func checkRequired() error {
}

if len(unsetFlags) > 0 {
log.Debug("checkRequired - unsetFlags: ", unsetFlags)
red := color.New(color.FgRed)
redB := color.New(color.FgRed, color.Bold)

Expand Down
5 changes: 2 additions & 3 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func TestDryRun(t *testing.T) {
}

// https://stackoverflow.com/a/33404435/1159410
func TestRequiredVars(t *testing.T) {
func TestCheckRequired(t *testing.T) {
assert := assert.New(t)
setup()
runTaskCount = 0
Expand All @@ -133,7 +133,7 @@ func TestRequiredVars(t *testing.T) {
return
}

c := exec.Command(os.Args[0], "-test.run=TestRequiredVars")
c := exec.Command(os.Args[0], "-test.run=TestCheckRequired")
c.Env = append(os.Environ(), "BE_CRASHER=1")
err := c.Run()

Expand Down Expand Up @@ -197,7 +197,6 @@ func TestConfigFile(t *testing.T) {
err := initConfigFile()

assert.Nil(err)
viper.Debug()
assert.Equal("test-cluster", viper.Get("cluster"))
assert.Equal("test-task", viper.Get("task"))
assert.Equal("sg1", viper.Get("security-group"))
Expand Down

0 comments on commit 6a724ea

Please sign in to comment.