Skip to content

Commit d6cbe8f

Browse files
committed
refactor: easier to read the flow
1 parent 300f6e0 commit d6cbe8f

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

cmd/cmd_root_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func Test_loadConfig_UseDefault(t *testing.T) {
5959

6060
var (
6161
expectExitCode int
62-
actualExitCode int = 1 // This should turn into 0
62+
actualExitCode int
6363
expectFlag bool
6464
actualFlag bool
6565

@@ -71,25 +71,27 @@ func Test_loadConfig_UseDefault(t *testing.T) {
7171

7272
// Assign mock of "osExit" to capture the exit-status-code.
7373
osExit = func(code int) {
74-
actualExitCode = 0
74+
actualExitCode = 0 // If PathFileConf is empty then should not reach here.
7575
}
7676

7777
var capturedMsg string = capturer.CaptureStderr(func() {
7878
// Test app defined non-existing file path
7979
confAppDummy = conf.TConfigApp{
8080
PathFileConf: "",
8181
PathDirConf: ".",
82-
NameFileConf: "config",
82+
NameFileConf: "dummy_config",
8383
NameTypeConf: "json",
8484
}
8585
confUserDummy.NameToGreet = "bar"
86-
expectExitCode = 0
86+
actualExitCode = 1
87+
expectExitCode = 1
8788
loadConfig(&confAppDummy, &confUserDummy)
8889
})
8990

9091
// Exit code assertion
9192
assert.Equal(t, expectExitCode, actualExitCode,
92-
"If app defined conf file does not exist and using default then should not exit. Captured STDERR:"+capturedMsg,
93+
"If app defined conf file does not exist and using default then should not call 'osExit()'."+
94+
"Captured STDERR:"+capturedMsg,
9395
)
9496
// Default flag assertion
9597
expectFlag = true

0 commit comments

Comments
 (0)