Skip to content

Commit

Permalink
style(token_test): satisfy linter
Browse files Browse the repository at this point in the history
We do not care to error check the return value of these function calls because we know
them to be error-free in our toy test examples.
  • Loading branch information
cannonpalms committed Nov 27, 2023
1 parent 798eecb commit 188de1e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ linters-settings:
- sigs.k8s.io/cluster-api

- github.com/cluster-api-provider-k3s/cluster-api-k3s

- github.com/google/uuid
gci:
sections:
- standard
Expand Down
25 changes: 20 additions & 5 deletions pkg/token/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/google/uuid"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand Down Expand Up @@ -163,7 +164,7 @@ func TestUpsertControllerRef(t *testing.T) {
controllee := newPod("controllee")
oldController := newPod("old-controller")
newController := newPod("new-controller")
controllerutil.SetControllerReference(oldController, controllee, scheme.Scheme)
setControllerReference(oldController, controllee, scheme.Scheme)

upsertControllerRef(controllee, newController)

Expand All @@ -180,7 +181,7 @@ func TestUpsertControllerRef(t *testing.T) {
controllee := newPod("controllee")
controller := newPod("controller")
otherObject := newPod("otherObject")
controllerutil.SetOwnerReference(otherObject, controllee, scheme.Scheme)
setOwnerReference(otherObject, controllee, scheme.Scheme)

upsertControllerRef(controllee, controller)

Expand All @@ -197,7 +198,7 @@ func TestUpsertControllerRef(t *testing.T) {
controllee := newPod("controllee")

otherObject := newPod("otherObject")
controllerutil.SetOwnerReference(otherObject, controllee, scheme.Scheme)
setOwnerReference(otherObject, controllee, scheme.Scheme)

oldController := newPod("old-controller")
existingControllerRef := metav1.NewControllerRef(oldController, oldController.GetObjectKind().GroupVersionKind())
Expand All @@ -217,7 +218,7 @@ func TestUpsertControllerRef(t *testing.T) {
}

func addOwnerRef(client client.Client, object, owner client.Object) error {
controllerutil.SetOwnerReference(owner, object, client.Scheme())
setOwnerReference(owner, object, client.Scheme())

if err := client.Update(context.Background(), object); err != nil {
return fmt.Errorf("failed to add owner to object: %v", err)
Expand All @@ -227,7 +228,7 @@ func addOwnerRef(client client.Client, object, owner client.Object) error {
}

// isOwnedBy returns a boolean based upon whether the provided object "owned"
// has an owner reference for the provided object "owner"
// has an owner reference for the provided object "owner".
func isOwnedBy(owned, owner metav1.Object) bool {
// Retrieve the owner references from the owned object
ownerReferences := owned.GetOwnerReferences()
Expand All @@ -241,3 +242,17 @@ func isOwnedBy(owned, owner metav1.Object) bool {

return false
}

// setOwnerReference is a helper function that wraps controllerutil.SetOwnerReference(...)
// with an //nolint:errcheck comment to suppress error check linters.
func setOwnerReference(owner, owned metav1.Object, scheme *runtime.Scheme) {
//nolint:errcheck
controllerutil.SetOwnerReference(owner, owned, scheme)
}

// setControllerReference is a helper function that wraps controllerutil.SetControllerReference(...)
// with an //nolint:errcheck comment to suppress error check linters.
func setControllerReference(owner, owned metav1.Object, scheme *runtime.Scheme) {
//nolint:errcheck
controllerutil.SetControllerReference(owner, owned, scheme)
}

0 comments on commit 188de1e

Please sign in to comment.