chore(lint): enable unnecessaryBlock rule from go-critic (#23404)

Signed-off-by: Matthieu MOREL <[email protected]>
This commit is contained in:
Matthieu MOREL
2025-06-16 10:00:55 -04:00
committed by GitHub
parent 29bd4c3730
commit 3e3451a8ee
4 changed files with 49 additions and 59 deletions
-1
View File
@@ -71,7 +71,6 @@ linters:
- tooManyResultsChecker
- typeDefFirst
- typeSwitchVar
- unnecessaryBlock
- unnamedResult
- whyNoLint
+17 -19
View File
@@ -2087,25 +2087,23 @@ func TestGetCachedAppState(t *testing.T) {
watcher := watch.NewFakeWithChanSize(1, true)
// Configure fakeClientSet within lock, before requesting cached app state, to avoid data race
{
fakeClientSet.Lock()
fakeClientSet.ReactionChain = nil
fakeClientSet.WatchReactionChain = nil
fakeClientSet.AddReactor("patch", "applications", func(_ kubetesting.Action) (handled bool, ret runtime.Object, err error) {
patched = true
updated := testApp.DeepCopy()
updated.ResourceVersion = "2"
appServer.appBroadcaster.OnUpdate(testApp, updated)
return true, testApp, nil
})
fakeClientSet.AddReactor("get", "applications", func(_ kubetesting.Action) (handled bool, ret runtime.Object, err error) {
return true, &v1alpha1.Application{Spec: v1alpha1.ApplicationSpec{Source: &v1alpha1.ApplicationSource{}}}, nil
})
fakeClientSet.Unlock()
fakeClientSet.AddWatchReactor("applications", func(_ kubetesting.Action) (handled bool, ret watch.Interface, err error) {
return true, watcher, nil
})
}
fakeClientSet.Lock()
fakeClientSet.ReactionChain = nil
fakeClientSet.WatchReactionChain = nil
fakeClientSet.AddReactor("patch", "applications", func(_ kubetesting.Action) (handled bool, ret runtime.Object, err error) {
patched = true
updated := testApp.DeepCopy()
updated.ResourceVersion = "2"
appServer.appBroadcaster.OnUpdate(testApp, updated)
return true, testApp, nil
})
fakeClientSet.AddReactor("get", "applications", func(_ kubetesting.Action) (handled bool, ret runtime.Object, err error) {
return true, &v1alpha1.Application{Spec: v1alpha1.ApplicationSpec{Source: &v1alpha1.ApplicationSource{}}}, nil
})
fakeClientSet.Unlock()
fakeClientSet.AddWatchReactor("applications", func(_ kubetesting.Action) (handled bool, ret watch.Interface, err error) {
return true, watcher, nil
})
err := appServer.getCachedAppState(t.Context(), testApp, func() error {
res := cache.ErrCacheMiss
+11 -13
View File
@@ -393,20 +393,18 @@ func extractKubeConfigValues() (string, string, error) {
var kubeConfigDefault string
paths := loadingRules.Precedence
{
// For all the kubeconfig paths, look for one that exists
for _, path := range paths {
_, err = os.Stat(path)
if err == nil {
// Success
kubeConfigDefault = path
break
} // Otherwise, continue.
}
// For all the kubeconfig paths, look for one that exists
for _, path := range paths {
_, err = os.Stat(path)
if err == nil {
// Success
kubeConfigDefault = path
break
} // Otherwise, continue.
}
if kubeConfigDefault == "" {
return "", "", stderrors.New("unable to retrieve kube config path")
}
if kubeConfigDefault == "" {
return "", "", stderrors.New("unable to retrieve kube config path")
}
kubeConfigContents, err := os.ReadFile(kubeConfigDefault)
+21 -26
View File
@@ -268,32 +268,27 @@ func TestContainsSyncResource(t *testing.T) {
// TestNilOutZerValueAppSources verifies we will nil out app source specs when they are their zero-value
func TestNilOutZerValueAppSources(t *testing.T) {
var spec *argoappv1.ApplicationSpec
{
spec = NormalizeApplicationSpec(&argoappv1.ApplicationSpec{Source: &argoappv1.ApplicationSource{Kustomize: &argoappv1.ApplicationSourceKustomize{NamePrefix: "foo"}}})
assert.NotNil(t, spec.GetSource().Kustomize)
spec = NormalizeApplicationSpec(&argoappv1.ApplicationSpec{Source: &argoappv1.ApplicationSource{Kustomize: &argoappv1.ApplicationSourceKustomize{NamePrefix: ""}}})
source := spec.GetSource()
assert.Nil(t, source.Kustomize)
}
{
spec = NormalizeApplicationSpec(&argoappv1.ApplicationSpec{Source: &argoappv1.ApplicationSource{Kustomize: &argoappv1.ApplicationSourceKustomize{NameSuffix: "foo"}}})
assert.NotNil(t, spec.GetSource().Kustomize)
spec = NormalizeApplicationSpec(&argoappv1.ApplicationSpec{Source: &argoappv1.ApplicationSource{Kustomize: &argoappv1.ApplicationSourceKustomize{NameSuffix: ""}}})
source := spec.GetSource()
assert.Nil(t, source.Kustomize)
}
{
spec = NormalizeApplicationSpec(&argoappv1.ApplicationSpec{Source: &argoappv1.ApplicationSource{Helm: &argoappv1.ApplicationSourceHelm{ValueFiles: []string{"values.yaml"}}}})
assert.NotNil(t, spec.GetSource().Helm)
spec = NormalizeApplicationSpec(&argoappv1.ApplicationSpec{Source: &argoappv1.ApplicationSource{Helm: &argoappv1.ApplicationSourceHelm{ValueFiles: []string{}}}})
assert.Nil(t, spec.GetSource().Helm)
}
{
spec = NormalizeApplicationSpec(&argoappv1.ApplicationSpec{Source: &argoappv1.ApplicationSource{Directory: &argoappv1.ApplicationSourceDirectory{Recurse: true}}})
assert.NotNil(t, spec.GetSource().Directory)
spec = NormalizeApplicationSpec(&argoappv1.ApplicationSpec{Source: &argoappv1.ApplicationSource{Directory: &argoappv1.ApplicationSourceDirectory{Recurse: false}}})
assert.Nil(t, spec.GetSource().Directory)
}
spec = NormalizeApplicationSpec(&argoappv1.ApplicationSpec{Source: &argoappv1.ApplicationSource{Kustomize: &argoappv1.ApplicationSourceKustomize{NamePrefix: "foo"}}})
assert.NotNil(t, spec.GetSource().Kustomize)
spec = NormalizeApplicationSpec(&argoappv1.ApplicationSpec{Source: &argoappv1.ApplicationSource{Kustomize: &argoappv1.ApplicationSourceKustomize{NamePrefix: ""}}})
source := spec.GetSource()
assert.Nil(t, source.Kustomize)
spec = NormalizeApplicationSpec(&argoappv1.ApplicationSpec{Source: &argoappv1.ApplicationSource{Kustomize: &argoappv1.ApplicationSourceKustomize{NameSuffix: "foo"}}})
assert.NotNil(t, spec.GetSource().Kustomize)
spec = NormalizeApplicationSpec(&argoappv1.ApplicationSpec{Source: &argoappv1.ApplicationSource{Kustomize: &argoappv1.ApplicationSourceKustomize{NameSuffix: ""}}})
source = spec.GetSource()
assert.Nil(t, source.Kustomize)
spec = NormalizeApplicationSpec(&argoappv1.ApplicationSpec{Source: &argoappv1.ApplicationSource{Helm: &argoappv1.ApplicationSourceHelm{ValueFiles: []string{"values.yaml"}}}})
assert.NotNil(t, spec.GetSource().Helm)
spec = NormalizeApplicationSpec(&argoappv1.ApplicationSpec{Source: &argoappv1.ApplicationSource{Helm: &argoappv1.ApplicationSourceHelm{ValueFiles: []string{}}}})
assert.Nil(t, spec.GetSource().Helm)
spec = NormalizeApplicationSpec(&argoappv1.ApplicationSpec{Source: &argoappv1.ApplicationSource{Directory: &argoappv1.ApplicationSourceDirectory{Recurse: true}}})
assert.NotNil(t, spec.GetSource().Directory)
spec = NormalizeApplicationSpec(&argoappv1.ApplicationSpec{Source: &argoappv1.ApplicationSource{Directory: &argoappv1.ApplicationSourceDirectory{Recurse: false}}})
assert.Nil(t, spec.GetSource().Directory)
}
func TestValidatePermissionsEmptyDestination(t *testing.T) {