1
0
mirror of https://github.com/aquasecurity/kube-bench.git synced 2024-12-19 05:08:07 +00:00

chore: fix defer func in for-loop (#825)

* chore: call defer func for each iteration

Signed-off-by: TakahiroTsuruda <isrgnoe@gmail.com>

* chore: error check
This commit is contained in:
Takahiro Tsuruda 2021-02-23 23:22:15 +09:00 committed by GitHub
parent baf05eca3b
commit 4d6de1e2a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 19 deletions

View File

@ -195,17 +195,19 @@ func TestIsMaster(t *testing.T) {
defer restore() defer restore()
for _, tc := range testCases { for _, tc := range testCases {
cfgFile = tc.cfgFile func() {
initConfig() cfgFile = tc.cfgFile
initConfig()
oldGetBinariesFunc := getBinariesFunc oldGetBinariesFunc := getBinariesFunc
getBinariesFunc = tc.getBinariesFunc getBinariesFunc = tc.getBinariesFunc
defer func() { defer func() {
getBinariesFunc = oldGetBinariesFunc getBinariesFunc = oldGetBinariesFunc
cfgFile = "" 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() defer restore()
for _, tc := range testCases { for _, tc := range testCases {
cfgFile = tc.cfgFile func() {
initConfig() cfgFile = tc.cfgFile
initConfig()
oldGetBinariesFunc := getBinariesFunc oldGetBinariesFunc := getBinariesFunc
getBinariesFunc = tc.getBinariesFunc getBinariesFunc = tc.getBinariesFunc
defer func() { defer func() {
getBinariesFunc = oldGetBinariesFunc getBinariesFunc = oldGetBinariesFunc
cfgFile = "" cfgFile = ""
}()
assert.Equal(t, tc.isEtcd, isEtcd(), tc.name)
}() }()
assert.Equal(t, tc.isEtcd, isEtcd(), tc.name)
} }
} }

View File

@ -52,7 +52,10 @@ var runCmd = &cobra.Command{
// Merge version-specific config if any. // Merge version-specific config if any.
path := filepath.Join(cfgDir, bv) 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) err = run(targets, bv)
if err != nil { if err != nil {