Skip to content

Commit 3826638

Browse files
authored
chore: enable testifylint linter (#657)
Signed-off-by: Matthieu MOREL <[email protected]>
1 parent 7e21b91 commit 3826638

File tree

7 files changed

+36
-27
lines changed

7 files changed

+36
-27
lines changed

.golangci.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
issues:
22
exclude-files:
33
- "pkg/diff/internal/fieldmanager/borrowed_.*\\.go$"
4+
linters:
5+
enable:
6+
- testifylint
7+
linters-settings:
8+
testifylint:
9+
enable-all: true
10+
disable:
11+
- go-require
12+
- require-error

pkg/cache/cluster_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,9 @@ metadata:
413413
return len(r.OwnerRefs) == 0
414414
})
415415
require.NoError(t, err)
416-
assert.Equal(t, managedObjs, map[kube.ResourceKey]*unstructured.Unstructured{
416+
assert.Equal(t, map[kube.ResourceKey]*unstructured.Unstructured{
417417
kube.NewResourceKey("apps", "Deployment", "default", "helm-guestbook"): mustToUnstructured(testDeploy()),
418-
})
418+
}, managedObjs)
419419
}
420420

421421
func TestGetManagedLiveObjsNamespacedModeClusterLevelResource(t *testing.T) {
@@ -466,7 +466,7 @@ metadata:
466466
_, err = cluster.GetManagedLiveObjs([]*unstructured.Unstructured{clusterLevelRes}, func(r *Resource) bool {
467467
return len(r.OwnerRefs) == 0
468468
})
469-
assert.Nil(t, err)
469+
assert.NoError(t, err)
470470

471471
otherNamespaceRes := strToUnstructured(`
472472
apiVersion: apps/v1
@@ -507,9 +507,9 @@ metadata:
507507
return len(r.OwnerRefs) == 0
508508
})
509509
require.NoError(t, err)
510-
assert.Equal(t, managedObjs, map[kube.ResourceKey]*unstructured.Unstructured{
510+
assert.Equal(t, map[kube.ResourceKey]*unstructured.Unstructured{
511511
kube.NewResourceKey("apps", "Deployment", "default", "helm-guestbook"): mustToUnstructured(testDeploy()),
512-
})
512+
}, managedObjs)
513513
}
514514

515515
func TestGetManagedLiveObjsValidNamespace(t *testing.T) {
@@ -535,9 +535,9 @@ metadata:
535535
return len(r.OwnerRefs) == 0
536536
})
537537
require.NoError(t, err)
538-
assert.Equal(t, managedObjs, map[kube.ResourceKey]*unstructured.Unstructured{
538+
assert.Equal(t, map[kube.ResourceKey]*unstructured.Unstructured{
539539
kube.NewResourceKey("apps", "Deployment", "default", "helm-guestbook"): mustToUnstructured(testDeploy()),
540-
})
540+
}, managedObjs)
541541
}
542542

543543
func TestGetManagedLiveObjsInvalidNamespace(t *testing.T) {
@@ -640,9 +640,9 @@ metadata:
640640
assert.NoError(t, err)
641641
assert.Equal(t, testCaseCopy.expectConvertToVersionCalled, convertToVersionWasCalled)
642642
assert.Equal(t, testCaseCopy.expectGetResourceCalled, getResourceWasCalled)
643-
assert.Equal(t, managedObjs, map[kube.ResourceKey]*unstructured.Unstructured{
643+
assert.Equal(t, map[kube.ResourceKey]*unstructured.Unstructured{
644644
kube.NewResourceKey(cronTabGroup, "CronTab", "default", "test-crontab"): mustToUnstructured(testCronTab()),
645-
})
645+
}, managedObjs)
646646
})
647647
}
648648
}

pkg/cache/predicates_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ func TestGetNamespaceResources(t *testing.T) {
8282

8383
resources := cluster.FindResources("default", TopLevelResource)
8484
assert.Len(t, resources, 2)
85-
assert.Equal(t, resources[getResourceKey(t, defaultNamespaceTopLevel1)].Ref.Name, "helm-guestbook1")
86-
assert.Equal(t, resources[getResourceKey(t, defaultNamespaceTopLevel2)].Ref.Name, "helm-guestbook2")
85+
assert.Equal(t, "helm-guestbook1", resources[getResourceKey(t, defaultNamespaceTopLevel1)].Ref.Name)
86+
assert.Equal(t, "helm-guestbook2", resources[getResourceKey(t, defaultNamespaceTopLevel2)].Ref.Name)
8787

8888
resources = cluster.FindResources("kube-system", TopLevelResource)
8989
assert.Len(t, resources, 1)
90-
assert.Equal(t, resources[getResourceKey(t, kubesystemNamespaceTopLevel2)].Ref.Name, "helm-guestbook3")
90+
assert.Equal(t, "helm-guestbook3", resources[getResourceKey(t, kubesystemNamespaceTopLevel2)].Ref.Name)
9191
}
9292

9393
func ExampleNewClusterCache_inspectNamespaceResources() {

pkg/diff/diff_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,9 @@ func TestDiffResourceWithInvalidField(t *testing.T) {
530530
diffRes := diff(t, &leftUn, rightUn, diffOptionsForTest()...)
531531
assert.True(t, diffRes.Modified)
532532
ascii, err := printDiff(diffRes)
533-
assert.Nil(t, err)
533+
assert.NoError(t, err)
534534

535-
assert.True(t, strings.Contains(ascii, "invalidKey"))
535+
assert.Contains(t, ascii, "invalidKey")
536536
if ascii != "" {
537537
t.Log(ascii)
538538
}
@@ -1375,7 +1375,7 @@ func TestHideSecretDataHandleEmptySecret(t *testing.T) {
13751375
assert.NoError(t, err)
13761376
assert.NotNil(t, target)
13771377
assert.NotNil(t, live)
1378-
assert.Equal(t, nil, target.Object["data"])
1378+
assert.Nil(t, target.Object["data"])
13791379
assert.Equal(t, map[string]interface{}{"namespace": "++++++++", "token": "++++++++"}, secretData(live))
13801380
}
13811381

pkg/sync/hook/helm/weight_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ import (
99
)
1010

1111
func TestWeight(t *testing.T) {
12-
assert.Equal(t, Weight(NewPod()), 0)
13-
assert.Equal(t, Weight(Annotate(NewPod(), "helm.sh/hook-weight", "1")), 1)
12+
assert.Equal(t, 0, Weight(NewPod()))
13+
assert.Equal(t, 1, Weight(Annotate(NewPod(), "helm.sh/hook-weight", "1")))
1414
}

pkg/sync/sync_context_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ func TestDoNotSyncOrPruneHooks(t *testing.T) {
688688
syncCtx.hooks = []*unstructured.Unstructured{targetPod, liveSvc}
689689
syncCtx.Sync()
690690
phase, _, resources := syncCtx.GetState()
691-
assert.Len(t, resources, 0)
691+
assert.Empty(t, resources)
692692
assert.Equal(t, synccommon.OperationSucceeded, phase)
693693
}
694694

@@ -1715,7 +1715,7 @@ func TestSetOperationFailed(t *testing.T) {
17151715

17161716
sc.setOperationFailed(nil, tasks, "one or more objects failed to apply")
17171717

1718-
assert.Equal(t, sc.message, "one or more objects failed to apply, reason: namespace not found")
1718+
assert.Equal(t, "one or more objects failed to apply, reason: namespace not found", sc.message)
17191719

17201720
}
17211721

@@ -1729,7 +1729,7 @@ func TestSetOperationFailedDuplicatedMessages(t *testing.T) {
17291729

17301730
sc.setOperationFailed(nil, tasks, "one or more objects failed to apply")
17311731

1732-
assert.Equal(t, sc.message, "one or more objects failed to apply, reason: namespace not found")
1732+
assert.Equal(t, "one or more objects failed to apply, reason: namespace not found", sc.message)
17331733

17341734
}
17351735

@@ -1739,7 +1739,7 @@ func TestSetOperationFailedNoTasks(t *testing.T) {
17391739

17401740
sc.setOperationFailed(nil, nil, "one or more objects failed to apply")
17411741

1742-
assert.Equal(t, sc.message, "one or more objects failed to apply")
1742+
assert.Equal(t, "one or more objects failed to apply", sc.message)
17431743

17441744
}
17451745

@@ -1990,7 +1990,7 @@ func TestWaitForCleanUpBeforeNextWave(t *testing.T) {
19901990
syncCtx.Sync()
19911991
phase, _, result = syncCtx.GetState()
19921992
assert.Equal(t, synccommon.OperationRunning, phase)
1993-
assert.Equal(t, 1, len(result))
1993+
assert.Len(t, result, 1)
19941994
assert.Equal(t, "pod-3", result[0].ResourceKey.Name)
19951995
assert.Equal(t, synccommon.ResultCodePruned, result[0].Status)
19961996

@@ -2004,7 +2004,7 @@ func TestWaitForCleanUpBeforeNextWave(t *testing.T) {
20042004
syncCtx.Sync()
20052005
phase, _, result = syncCtx.GetState()
20062006
assert.Equal(t, synccommon.OperationRunning, phase)
2007-
assert.Equal(t, 2, len(result))
2007+
assert.Len(t, result, 2)
20082008
assert.Equal(t, "pod-2", result[1].ResourceKey.Name)
20092009
assert.Equal(t, synccommon.ResultCodePruned, result[1].Status)
20102010

@@ -2017,7 +2017,7 @@ func TestWaitForCleanUpBeforeNextWave(t *testing.T) {
20172017
phase, msg, result = syncCtx.GetState()
20182018
assert.Equal(t, synccommon.OperationRunning, phase)
20192019
assert.Equal(t, "waiting for deletion of /Pod/pod-2", msg)
2020-
assert.Equal(t, 2, len(result))
2020+
assert.Len(t, result, 2)
20212021

20222022
// simulate successful delete of pod2
20232023
syncCtx.resources = groupResources(ReconciliationResult{
@@ -2030,7 +2030,7 @@ func TestWaitForCleanUpBeforeNextWave(t *testing.T) {
20302030
syncCtx.Sync()
20312031
phase, _, result = syncCtx.GetState()
20322032
assert.Equal(t, synccommon.OperationSucceeded, phase)
2033-
assert.Equal(t, 3, len(result))
2033+
assert.Len(t, result, 3)
20342034
assert.Equal(t, "pod-3", result[0].ResourceKey.Name)
20352035
assert.Equal(t, "pod-2", result[1].ResourceKey.Name)
20362036
assert.Equal(t, "pod-1", result[2].ResourceKey.Name)

pkg/utils/kube/kube_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestUnsetLabels(t *testing.T) {
6262
func TestCleanKubectlOutput(t *testing.T) {
6363
{
6464
s := `error: error validating "STDIN": error validating data: ValidationError(Deployment.spec): missing required field "selector" in io.k8s.api.apps.v1beta2.DeploymentSpec; if you choose to ignore these errors, turn validation off with --validate=false`
65-
assert.Equal(t, cleanKubectlOutput(s), `error validating data: ValidationError(Deployment.spec): missing required field "selector" in io.k8s.api.apps.v1beta2.DeploymentSpec`)
65+
assert.Equal(t, `error validating data: ValidationError(Deployment.spec): missing required field "selector" in io.k8s.api.apps.v1beta2.DeploymentSpec`, cleanKubectlOutput(s))
6666
}
6767
{
6868
s := `error when applying patch:
@@ -72,7 +72,7 @@ Resource: "/v1, Resource=services", GroupVersionKind: "/v1, Kind=Service"
7272
Name: "my-service", Namespace: "argocd-e2e--test-immutable-change-ysfud"
7373
Object: &{map["apiVersion":"v1" "kind":"Service" "metadata":map["annotations":map["kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"v1\",\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"labels\":{\"app.kubernetes.io/instance\":\"test-immutable-change\"},\"name\":\"my-service\",\"namespace\":\"argocd-e2e--test-immutable-change-ysfud\"},\"spec\":{\"clusterIP\":\"10.96.0.43\",\"ports\":[{\"port\":80,\"protocol\":\"TCP\",\"targetPort\":9376}],\"selector\":{\"app\":\"MyApp\"}}}\n"] "creationTimestamp":"2019-12-11T15:29:56Z" "labels":map["app.kubernetes.io/instance":"test-immutable-change"] "name":"my-service" "namespace":"argocd-e2e--test-immutable-change-ysfud" "resourceVersion":"157426" "selfLink":"/api/v1/namespaces/argocd-e2e--test-immutable-change-ysfud/services/my-service" "uid":"339cf96f-47eb-4759-ac95-30a169dce004"] "spec":map["clusterIP":"10.96.0.43" "ports":[map["port":'P' "protocol":"TCP" "targetPort":'\u24a0']] "selector":map["app":"MyApp"] "sessionAffinity":"None" "type":"ClusterIP"] "status":map["loadBalancer":map[]]]}
7474
for: "/var/folders/_m/991sn1ds7g39lnbhp6wvqp9d_j5476/T/224503547": Service "my-service" is invalid: spec.clusterIP: Invalid value: "10.96.0.44": field is immutable`
75-
assert.Equal(t, cleanKubectlOutput(s), `Service "my-service" is invalid: spec.clusterIP: Invalid value: "10.96.0.44": field is immutable`)
75+
assert.Equal(t, `Service "my-service" is invalid: spec.clusterIP: Invalid value: "10.96.0.44": field is immutable`, cleanKubectlOutput(s))
7676
}
7777
{
7878
s := `error when patching "/var/folders/mj/c96jcs7j2cq7xcjfhqjq3m2w0000gn/T/745145319": "" is invalid: patch: Invalid value: "map[data:map[email:aaaaa password:<nil> username:<nil>] metadata:map[annotations:map[kubectl.kubernetes.io/last-applied-configuration:{\"apiVersion\":\"v1\",\"data\":{\"email\":\"aaaaa\"},\"kind\":\"Secret\",\"metadata\":{\"annotations\":{},\"labels\":{\"app.kubernetes.io/instance\":\"test\"},\"name\":\"my-secret\",\"namespace\":\"default\"},\"stringData\":{\"id\":1,\"password\":0,\"username\":\"username\"},\"type\":\"Opaque\"}\n]] stringData:map[id:1 password:0 username:username]]": error decoding from json: illegal base64 data at input byte 4`

0 commit comments

Comments
 (0)