Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enable testifylint linter #657

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
issues:
exclude-files:
- "pkg/diff/internal/fieldmanager/borrowed_.*\\.go$"
linters:
enable:
- testifylint
linters-settings:
testifylint:
enable-all: true
disable:
- go-require
- require-error
18 changes: 9 additions & 9 deletions pkg/cache/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,9 @@ metadata:
return len(r.OwnerRefs) == 0
})
require.NoError(t, err)
assert.Equal(t, managedObjs, map[kube.ResourceKey]*unstructured.Unstructured{
assert.Equal(t, map[kube.ResourceKey]*unstructured.Unstructured{
kube.NewResourceKey("apps", "Deployment", "default", "helm-guestbook"): mustToUnstructured(testDeploy()),
})
}, managedObjs)
}

func TestGetManagedLiveObjsNamespacedModeClusterLevelResource(t *testing.T) {
Expand Down Expand Up @@ -424,7 +424,7 @@ metadata:
_, err = cluster.GetManagedLiveObjs([]*unstructured.Unstructured{clusterLevelRes}, func(r *Resource) bool {
return len(r.OwnerRefs) == 0
})
assert.Nil(t, err)
assert.NoError(t, err)

otherNamespaceRes := strToUnstructured(`
apiVersion: apps/v1
Expand Down Expand Up @@ -465,9 +465,9 @@ metadata:
return len(r.OwnerRefs) == 0
})
require.NoError(t, err)
assert.Equal(t, managedObjs, map[kube.ResourceKey]*unstructured.Unstructured{
assert.Equal(t, map[kube.ResourceKey]*unstructured.Unstructured{
kube.NewResourceKey("apps", "Deployment", "default", "helm-guestbook"): mustToUnstructured(testDeploy()),
})
}, managedObjs)
}

func TestGetManagedLiveObjsValidNamespace(t *testing.T) {
Expand All @@ -493,9 +493,9 @@ metadata:
return len(r.OwnerRefs) == 0
})
require.NoError(t, err)
assert.Equal(t, managedObjs, map[kube.ResourceKey]*unstructured.Unstructured{
assert.Equal(t, map[kube.ResourceKey]*unstructured.Unstructured{
kube.NewResourceKey("apps", "Deployment", "default", "helm-guestbook"): mustToUnstructured(testDeploy()),
})
}, managedObjs)
}

func TestGetManagedLiveObjsInvalidNamespace(t *testing.T) {
Expand Down Expand Up @@ -598,9 +598,9 @@ metadata:
assert.NoError(t, err)
assert.Equal(t, testCaseCopy.expectConvertToVersionCalled, convertToVersionWasCalled)
assert.Equal(t, testCaseCopy.expectGetResourceCalled, getResourceWasCalled)
assert.Equal(t, managedObjs, map[kube.ResourceKey]*unstructured.Unstructured{
assert.Equal(t, map[kube.ResourceKey]*unstructured.Unstructured{
kube.NewResourceKey(cronTabGroup, "CronTab", "default", "test-crontab"): mustToUnstructured(testCronTab()),
})
}, managedObjs)
})
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/cache/predicates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ func TestGetNamespaceResources(t *testing.T) {

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

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

func ExampleNewClusterCache_inspectNamespaceResources() {
Expand Down
6 changes: 3 additions & 3 deletions pkg/diff/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,9 @@ func TestDiffResourceWithInvalidField(t *testing.T) {
diffRes := diff(t, &leftUn, rightUn, diffOptionsForTest()...)
assert.True(t, diffRes.Modified)
ascii, err := printDiff(diffRes)
assert.Nil(t, err)
assert.NoError(t, err)

assert.True(t, strings.Contains(ascii, "invalidKey"))
assert.Contains(t, ascii, "invalidKey")
if ascii != "" {
t.Log(ascii)
}
Expand Down Expand Up @@ -1255,7 +1255,7 @@ func TestHideSecretDataHandleEmptySecret(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, target)
assert.NotNil(t, live)
assert.Equal(t, nil, target.Object["data"])
assert.Nil(t, target.Object["data"])
assert.Equal(t, map[string]interface{}{"namespace": "++++++++", "token": "++++++++"}, secretData(live))
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/sync/hook/helm/weight_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import (
)

func TestWeight(t *testing.T) {
assert.Equal(t, Weight(NewPod()), 0)
assert.Equal(t, Weight(Annotate(NewPod(), "helm.sh/hook-weight", "1")), 1)
assert.Equal(t, 0, Weight(NewPod()))
assert.Equal(t, 1, Weight(Annotate(NewPod(), "helm.sh/hook-weight", "1")))
}
16 changes: 8 additions & 8 deletions pkg/sync/sync_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ func TestDoNotSyncOrPruneHooks(t *testing.T) {
syncCtx.hooks = []*unstructured.Unstructured{targetPod, liveSvc}
syncCtx.Sync()
phase, _, resources := syncCtx.GetState()
assert.Len(t, resources, 0)
assert.Empty(t, resources)
assert.Equal(t, synccommon.OperationSucceeded, phase)
}

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

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

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

}

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

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

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

}

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

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

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

}

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

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

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

// simulate successful delete of pod2
syncCtx.resources = groupResources(ReconciliationResult{
Expand All @@ -2030,7 +2030,7 @@ func TestWaitForCleanUpBeforeNextWave(t *testing.T) {
syncCtx.Sync()
phase, _, result = syncCtx.GetState()
assert.Equal(t, synccommon.OperationSucceeded, phase)
assert.Equal(t, 3, len(result))
assert.Len(t, result, 3)
assert.Equal(t, "pod-3", result[0].ResourceKey.Name)
assert.Equal(t, "pod-2", result[1].ResourceKey.Name)
assert.Equal(t, "pod-1", result[2].ResourceKey.Name)
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/kube/kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestUnsetLabels(t *testing.T) {
func TestCleanKubectlOutput(t *testing.T) {
{
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`
assert.Equal(t, cleanKubectlOutput(s), `error validating data: ValidationError(Deployment.spec): missing required field "selector" in io.k8s.api.apps.v1beta2.DeploymentSpec`)
assert.Equal(t, `error validating data: ValidationError(Deployment.spec): missing required field "selector" in io.k8s.api.apps.v1beta2.DeploymentSpec`, cleanKubectlOutput(s))
}
{
s := `error when applying patch:
Expand All @@ -72,7 +72,7 @@ Resource: "/v1, Resource=services", GroupVersionKind: "/v1, Kind=Service"
Name: "my-service", Namespace: "argocd-e2e--test-immutable-change-ysfud"
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[]]]}
for: "/var/folders/_m/991sn1ds7g39lnbhp6wvqp9d_j5476/T/224503547": Service "my-service" is invalid: spec.clusterIP: Invalid value: "10.96.0.44": field is immutable`
assert.Equal(t, cleanKubectlOutput(s), `Service "my-service" is invalid: spec.clusterIP: Invalid value: "10.96.0.44": field is immutable`)
assert.Equal(t, `Service "my-service" is invalid: spec.clusterIP: Invalid value: "10.96.0.44": field is immutable`, cleanKubectlOutput(s))
}
}

Expand Down
Loading