cleanup: address golangci 'usetesting' linter issues

When a context.Context is needed in a unit test, t.Context() should be
used instead of creating a new one with context.TODO() or
context.Background().

Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
Niels de Vos
2025-04-29 11:36:03 +02:00
committed by mergify[bot]
parent be5462cf62
commit 457ffe884a
19 changed files with 35 additions and 51 deletions

View File

@ -14,7 +14,6 @@ limitations under the License.
package rbd
import (
"context"
"testing"
"github.com/csi-addons/spec/lib/go/fence"
@ -35,7 +34,7 @@ func TestFenceClusterNetwork(t *testing.T) {
Cidrs: nil,
}
_, err := controller.FenceClusterNetwork(context.TODO(), req)
_, err := controller.FenceClusterNetwork(t.Context(), req)
require.Error(t, err)
}
@ -51,6 +50,6 @@ func TestUnfenceClusterNetwork(t *testing.T) {
Secrets: nil,
Cidrs: nil,
}
_, err := controller.UnfenceClusterNetwork(context.TODO(), req)
_, err := controller.UnfenceClusterNetwork(t.Context(), req)
require.Error(t, err)
}

View File

@ -17,7 +17,6 @@ limitations under the License.
package rbd
import (
"context"
"testing"
"github.com/ceph/ceph-csi/internal/util"
@ -39,7 +38,7 @@ func TestControllerReclaimSpace(t *testing.T) {
Secrets: nil,
}
_, err := controller.ControllerReclaimSpace(context.TODO(), req)
_, err := controller.ControllerReclaimSpace(t.Context(), req)
require.Error(t, err)
}
@ -58,6 +57,6 @@ func TestNodeReclaimSpace(t *testing.T) {
Secrets: nil,
}
_, err := node.NodeReclaimSpace(context.TODO(), req)
_, err := node.NodeReclaimSpace(t.Context(), req)
require.Error(t, err)
}

View File

@ -83,7 +83,7 @@ func TestValidateSchedulingInterval(t *testing.T) {
func TestValidateSchedulingDetails(t *testing.T) {
t.Parallel()
ctx := context.TODO()
ctx := t.Context()
tests := []struct {
name string
parameters map[string]string
@ -213,7 +213,7 @@ func TestGetSchedulingDetails(t *testing.T) {
}
func TestCheckVolumeResyncStatus(t *testing.T) {
ctx := context.TODO()
ctx := t.Context()
t.Parallel()
tests := []struct {
name string
@ -406,7 +406,7 @@ func TestCheckRemoteSiteStatus(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if ready := checkRemoteSiteStatus(context.TODO(), tt.args.GetAllSitesStatus()); ready != tt.wantReady {
if ready := checkRemoteSiteStatus(t.Context(), tt.args.GetAllSitesStatus()); ready != tt.wantReady {
t.Errorf("checkRemoteSiteStatus() ready = %v, expect ready = %v", ready, tt.wantReady)
}
})
@ -546,7 +546,7 @@ func Test_getFlattenMode(t *testing.T) {
{
name: "flattenMode option not set",
args: args{
ctx: context.TODO(),
ctx: t.Context(),
parameters: map[string]string{},
},
want: types.FlattenModeNever,
@ -554,7 +554,7 @@ func Test_getFlattenMode(t *testing.T) {
{
name: "flattenMode option set to never",
args: args{
ctx: context.TODO(),
ctx: t.Context(),
parameters: map[string]string{
flattenModeKey: string(types.FlattenModeNever),
},
@ -564,7 +564,7 @@ func Test_getFlattenMode(t *testing.T) {
{
name: "flattenMode option set to force",
args: args{
ctx: context.TODO(),
ctx: t.Context(),
parameters: map[string]string{
flattenModeKey: string(types.FlattenModeForce),
},
@ -575,7 +575,7 @@ func Test_getFlattenMode(t *testing.T) {
{
name: "flattenMode option set to invalid value",
args: args{
ctx: context.TODO(),
ctx: t.Context(),
parameters: map[string]string{
flattenModeKey: "invalid123",
},