Skip to content

Commit 6a724ea

Browse files
committed
Fixes + cleans up tests
1 parent fac8139 commit 6a724ea

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

cmd/init.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ var InitCmd = &cobra.Command{
1111
Use: "init",
1212
Short: "Creates a blank `ecsrun.yml` config file in the current directory.",
1313
Run: func(cmd *cobra.Command, args []string) {
14+
// Reset viper as it carries over config from root. We want to build our own config.
15+
viper.Reset()
16+
1417
initCmd()
1518
},
1619
}
1720

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

2223
config := make(map[string]interface{})
2324
config["default"] = map[string]interface{}{

cmd/init_test.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ var testFs = afero.NewMemMapFs()
1717
func TestInitCmd(t *testing.T) {
1818
assert := assert.New(t)
1919

20-
viper.SetFs(testFs)
21-
2220
exists, err := afero.Exists(testFs, "./ecsrun.yaml")
2321
if err != nil {
2422
panic(err)
2523
}
2624
assert.False(exists)
2725

26+
viper.SetFs(testFs)
27+
2828
initCmd()
2929

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

3636
testFs.Remove("./ecsrun.yaml")
37+
38+
// Set back the FS to not affect other tests
39+
viper.SetFs(afero.NewOsFs())
3740
}

cmd/root.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ type VersionInfo struct {
2929
BuiltBy string
3030
}
3131

32-
var vInfo VersionInfo
33-
3432
func (v VersionInfo) String() string {
3533
return fmt.Sprintf(
3634
"ecsrun version info\nVersion: %s\nCommit: %s\nDate Built: %s\nBuilt By: %s\n",
@@ -40,11 +38,13 @@ func (v VersionInfo) String() string {
4038
v.BuiltBy)
4139
}
4240

43-
var log = logrus.New()
44-
45-
var fs = afero.NewOsFs()
46-
47-
var newEcsClient func(*RunConfig) ECSClient
41+
var (
42+
vInfo VersionInfo
43+
log = logrus.New()
44+
fs = afero.NewOsFs()
45+
newEcsClient func(*RunConfig) ECSClient
46+
cyan = color.New(color.FgCyan, color.Bold)
47+
)
4848

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

7878
// If we're running with --dry-run then print the input and exit.
7979
if viper.GetBool("dry-run") {
80-
cyan := color.New(color.FgCyan, color.Bold)
8180
cyan.Printf("DryRun! RunTaskInput:\n")
82-
8381
fmt.Println(prettyString)
8482

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

92+
cyan.Printf("RunTaskOutput: \n")
9493
prettyOut, _ := prettyjson.Marshal(output)
95-
log.Info("RunTaskOutput: ", string(prettyOut))
94+
fmt.Println(string(prettyOut))
9695
},
9796
}
9897

@@ -316,6 +315,7 @@ func checkRequired() error {
316315
}
317316

318317
if len(unsetFlags) > 0 {
318+
log.Debug("checkRequired - unsetFlags: ", unsetFlags)
319319
red := color.New(color.FgRed)
320320
redB := color.New(color.FgRed, color.Bold)
321321

cmd/root_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func TestDryRun(t *testing.T) {
120120
}
121121

122122
// https://stackoverflow.com/a/33404435/1159410
123-
func TestRequiredVars(t *testing.T) {
123+
func TestCheckRequired(t *testing.T) {
124124
assert := assert.New(t)
125125
setup()
126126
runTaskCount = 0
@@ -133,7 +133,7 @@ func TestRequiredVars(t *testing.T) {
133133
return
134134
}
135135

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

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

199199
assert.Nil(err)
200-
viper.Debug()
201200
assert.Equal("test-cluster", viper.Get("cluster"))
202201
assert.Equal("test-task", viper.Get("task"))
203202
assert.Equal("sg1", viper.Get("security-group"))

0 commit comments

Comments
 (0)