From 4d6de1e2a5fcd14e70380e4d59ec5641af63d47e Mon Sep 17 00:00:00 2001 From: Takahiro Tsuruda Date: Tue, 23 Feb 2021 23:22:15 +0900 Subject: [PATCH] chore: fix defer func in for-loop (#825) * chore: call defer func for each iteration Signed-off-by: TakahiroTsuruda * chore: error check --- cmd/common_test.go | 40 ++++++++++++++++++++++------------------ cmd/run.go | 5 ++++- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/cmd/common_test.go b/cmd/common_test.go index 60fb234..048ed4b 100644 --- a/cmd/common_test.go +++ b/cmd/common_test.go @@ -195,17 +195,19 @@ func TestIsMaster(t *testing.T) { defer restore() for _, tc := range testCases { - cfgFile = tc.cfgFile - initConfig() + func() { + cfgFile = tc.cfgFile + initConfig() - oldGetBinariesFunc := getBinariesFunc - getBinariesFunc = tc.getBinariesFunc - defer func() { - getBinariesFunc = oldGetBinariesFunc - cfgFile = "" + oldGetBinariesFunc := getBinariesFunc + getBinariesFunc = tc.getBinariesFunc + defer func() { + getBinariesFunc = oldGetBinariesFunc + cfgFile = "" + }() + + assert.Equal(t, tc.isMaster, isMaster(), tc.name) }() - - assert.Equal(t, tc.isMaster, isMaster(), tc.name) } } @@ -506,17 +508,19 @@ func TestIsEtcd(t *testing.T) { defer restore() for _, tc := range testCases { - cfgFile = tc.cfgFile - initConfig() + func() { + cfgFile = tc.cfgFile + initConfig() - oldGetBinariesFunc := getBinariesFunc - getBinariesFunc = tc.getBinariesFunc - defer func() { - getBinariesFunc = oldGetBinariesFunc - cfgFile = "" + oldGetBinariesFunc := getBinariesFunc + getBinariesFunc = tc.getBinariesFunc + defer func() { + getBinariesFunc = oldGetBinariesFunc + cfgFile = "" + }() + + assert.Equal(t, tc.isEtcd, isEtcd(), tc.name) }() - - assert.Equal(t, tc.isEtcd, isEtcd(), tc.name) } } diff --git a/cmd/run.go b/cmd/run.go index 20199c5..16b6641 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -52,7 +52,10 @@ var runCmd = &cobra.Command{ // Merge version-specific config if any. path := filepath.Join(cfgDir, bv) - mergeConfig(path) + err = mergeConfig(path) + if err != nil { + fmt.Printf("Error in mergeConfig: %v\n", err) + } err = run(targets, bv) if err != nil {