diff --git a/internal/cephfs/groupcontrollerserver_test.go b/internal/cephfs/groupcontrollerserver_test.go index a505064c7..8374d15b9 100644 --- a/internal/cephfs/groupcontrollerserver_test.go +++ b/internal/cephfs/groupcontrollerserver_test.go @@ -47,7 +47,7 @@ func TestControllerServer_validateCreateVolumeGroupSnapshotRequest(t *testing.T) { "valid CreateVolumeGroupSnapshotRequest", args{ - context.Background(), &csi.CreateVolumeGroupSnapshotRequest{ + t.Context(), &csi.CreateVolumeGroupSnapshotRequest{ Name: "vg-snap-1", SourceVolumeIds: []string{"vg-1"}, Parameters: map[string]string{ @@ -62,7 +62,7 @@ func TestControllerServer_validateCreateVolumeGroupSnapshotRequest(t *testing.T) { "empty request name in CreateVolumeGroupSnapshotRequest", args{ - context.Background(), &csi.CreateVolumeGroupSnapshotRequest{ + t.Context(), &csi.CreateVolumeGroupSnapshotRequest{ SourceVolumeIds: []string{"vg-1"}, }, }, @@ -72,7 +72,7 @@ func TestControllerServer_validateCreateVolumeGroupSnapshotRequest(t *testing.T) { "empty SourceVolumeIds in CreateVolumeGroupSnapshotRequest", args{ - context.Background(), &csi.CreateVolumeGroupSnapshotRequest{ + t.Context(), &csi.CreateVolumeGroupSnapshotRequest{ Name: "vg-snap-1", SourceVolumeIds: []string{"vg-1"}, }, @@ -83,7 +83,7 @@ func TestControllerServer_validateCreateVolumeGroupSnapshotRequest(t *testing.T) { "empty clusterID in CreateVolumeGroupSnapshotRequest", args{ - context.Background(), &csi.CreateVolumeGroupSnapshotRequest{ + t.Context(), &csi.CreateVolumeGroupSnapshotRequest{ Name: "vg-snap-1", SourceVolumeIds: []string{"vg-1"}, Parameters: map[string]string{"fsName": "value"}, @@ -95,7 +95,7 @@ func TestControllerServer_validateCreateVolumeGroupSnapshotRequest(t *testing.T) { "empty fsName in CreateVolumeGroupSnapshotRequest", args{ - context.Background(), &csi.CreateVolumeGroupSnapshotRequest{ + t.Context(), &csi.CreateVolumeGroupSnapshotRequest{ Name: "vg-snap-1", SourceVolumeIds: []string{"vg-1"}, Parameters: map[string]string{"clusterID": "value"}, diff --git a/internal/csi-addons/cephfs/network_fence_test.go b/internal/csi-addons/cephfs/network_fence_test.go index e24c33fab..f3629fbf3 100644 --- a/internal/csi-addons/cephfs/network_fence_test.go +++ b/internal/csi-addons/cephfs/network_fence_test.go @@ -17,7 +17,6 @@ limitations under the License. package cephfs import ( - "context" "testing" "github.com/csi-addons/spec/lib/go/fence" @@ -38,7 +37,7 @@ func TestFenceClusterNetwork(t *testing.T) { Cidrs: nil, } - _, err := controller.FenceClusterNetwork(context.TODO(), req) + _, err := controller.FenceClusterNetwork(t.Context(), req) require.Error(t, err) } @@ -54,6 +53,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) } diff --git a/internal/csi-addons/networkfence/fencing_test.go b/internal/csi-addons/networkfence/fencing_test.go index 4a6914685..3e4448f0e 100644 --- a/internal/csi-addons/networkfence/fencing_test.go +++ b/internal/csi-addons/networkfence/fencing_test.go @@ -17,7 +17,6 @@ limitations under the License. package networkfence import ( - "context" "testing" "github.com/stretchr/testify/require" @@ -252,7 +251,7 @@ listed 1 entries`, t.Run(tc.name, func(t *testing.T) { t.Parallel() - result := nf.parseBlocklistForCIDR(context.TODO(), tc.blocklist, tc.cidr) + result := nf.parseBlocklistForCIDR(t.Context(), tc.blocklist, tc.cidr) require.Equal(t, tc.expected, result) }) } diff --git a/internal/csi-addons/rbd/network_fence_test.go b/internal/csi-addons/rbd/network_fence_test.go index 260a854d6..901fbc320 100644 --- a/internal/csi-addons/rbd/network_fence_test.go +++ b/internal/csi-addons/rbd/network_fence_test.go @@ -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) } diff --git a/internal/csi-addons/rbd/reclaimspace_test.go b/internal/csi-addons/rbd/reclaimspace_test.go index 2ad51f9a2..ed129f418 100644 --- a/internal/csi-addons/rbd/reclaimspace_test.go +++ b/internal/csi-addons/rbd/reclaimspace_test.go @@ -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) } diff --git a/internal/csi-addons/rbd/replication_test.go b/internal/csi-addons/rbd/replication_test.go index ab378d2c5..b341f158b 100644 --- a/internal/csi-addons/rbd/replication_test.go +++ b/internal/csi-addons/rbd/replication_test.go @@ -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", }, diff --git a/internal/csi-common/utils_test.go b/internal/csi-common/utils_test.go index 9ca2a9105..2df39da72 100644 --- a/internal/csi-common/utils_test.go +++ b/internal/csi-common/utils_test.go @@ -17,7 +17,6 @@ limitations under the License. package csicommon import ( - "context" "os" "path/filepath" "strings" @@ -233,7 +232,7 @@ func TestFilesystemNodeGetVolumeStats(t *testing.T) { // retry until a mountpoint is found for { - stats, err := FilesystemNodeGetVolumeStats(context.TODO(), mount.New(""), cwd, true) + stats, err := FilesystemNodeGetVolumeStats(t.Context(), mount.New(""), cwd, true) if err != nil && cwd != "/" && strings.HasSuffix(err.Error(), "is not mounted") { // try again with the parent directory cwd = filepath.Dir(cwd) diff --git a/internal/kms/secretskms_test.go b/internal/kms/secretskms_test.go index d30d1ba67..698c6a72c 100644 --- a/internal/kms/secretskms_test.go +++ b/internal/kms/secretskms_test.go @@ -17,7 +17,6 @@ limitations under the License. package kms import ( - "context" "testing" "github.com/stretchr/testify/require" @@ -93,7 +92,7 @@ func TestWorkflowSecretsMetadataKMS(t *testing.T) { // plainDEK is the (LUKS) passphrase for the volume plainDEK := "usually created with generateNewEncryptionPassphrase()" - ctx := context.TODO() + ctx := t.Context() // with missing encryptionPassphraseKey, encrypting should fail _, err = kms.EncryptDEK(ctx, volumeID, plainDEK) diff --git a/internal/rbd/controllerserver_test.go b/internal/rbd/controllerserver_test.go index d7d55ca0d..3fcd87162 100644 --- a/internal/rbd/controllerserver_test.go +++ b/internal/rbd/controllerserver_test.go @@ -17,7 +17,6 @@ limitations under the License. package rbd import ( - "context" "testing" ) @@ -160,7 +159,7 @@ func TestToCSIVolume(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { t.Parallel() - if _, err := tt.rv.ToCSI(context.TODO()); (err != nil) != tt.wantErr { + if _, err := tt.rv.ToCSI(t.Context()); (err != nil) != tt.wantErr { t.Errorf("ToCSI() error = %v, wantErr %v", err, tt.wantErr) } }) diff --git a/internal/rbd/manager_test.go b/internal/rbd/manager_test.go index 42cb35639..550c85018 100644 --- a/internal/rbd/manager_test.go +++ b/internal/rbd/manager_test.go @@ -17,7 +17,6 @@ limitations under the License. package rbd import ( - "context" "testing" ) @@ -84,7 +83,7 @@ func TestMakeVolumeGroupID(t *testing.T) { t.Run(tt.name, func(t *testing.T) { t.Parallel() - ctx := context.TODO() + ctx := t.Context() mgr := NewManager("rbd.example.org", tt.parameters, nil) defer mgr.Destroy(ctx) diff --git a/internal/rbd/mirror_test.go b/internal/rbd/mirror_test.go index 7dc78e8f0..56a36364a 100644 --- a/internal/rbd/mirror_test.go +++ b/internal/rbd/mirror_test.go @@ -17,7 +17,6 @@ limitations under the License. package rbd import ( - "context" "strings" "testing" @@ -27,7 +26,6 @@ import ( func TestValidateLastSyncInfo(t *testing.T) { t.Parallel() - ctx := context.TODO() duration := int64(56743) zero := int64(0) @@ -124,7 +122,7 @@ func TestValidateLastSyncInfo(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { t.Parallel() - teststruct, err := newSyncInfo(ctx, tt.description) + teststruct, err := newSyncInfo(t.Context(), tt.description) if err != nil && !strings.Contains(err.Error(), tt.expectedErr) { // returned error t.Errorf("newSyncInfo() returned error, expected: %v, got: %v", diff --git a/internal/rbd/nodeserver_test.go b/internal/rbd/nodeserver_test.go index bc4ea7d3b..4ebe121c1 100644 --- a/internal/rbd/nodeserver_test.go +++ b/internal/rbd/nodeserver_test.go @@ -17,7 +17,6 @@ limitations under the License. package rbd import ( - "context" "encoding/json" "os" "testing" @@ -67,7 +66,7 @@ func TestGetStagingPath(t *testing.T) { func TestParseBoolOption(t *testing.T) { t.Parallel() - ctx := context.TODO() + ctx := t.Context() optionName := "myOption" defaultValue := false diff --git a/internal/rbd/qos_test.go b/internal/rbd/qos_test.go index 445ad55e0..f5a21e323 100644 --- a/internal/rbd/qos_test.go +++ b/internal/rbd/qos_test.go @@ -17,7 +17,6 @@ limitations under the License. package rbd import ( - "context" "testing" ) @@ -41,7 +40,7 @@ func checkQOS( func TestSetQOS(t *testing.T) { t.Parallel() - ctx := context.TODO() + ctx := t.Context() tests := map[string]string{ baseReadIops: "2000", diff --git a/internal/rbd/rbd_util_test.go b/internal/rbd/rbd_util_test.go index 2375f2c4c..edfd80d75 100644 --- a/internal/rbd/rbd_util_test.go +++ b/internal/rbd/rbd_util_test.go @@ -17,7 +17,6 @@ limitations under the License. package rbd import ( - "context" "errors" "os" "strings" @@ -249,7 +248,7 @@ func TestGetCephClientLogFileName(t *testing.T) { func TestStrategicActionOnLogFile(t *testing.T) { t.Parallel() - ctx := context.TODO() + ctx := t.Context() tmpDir := t.TempDir() var logFile [3]string @@ -320,7 +319,7 @@ func TestStrategicActionOnLogFile(t *testing.T) { func TestIsKrbdFeatureSupported(t *testing.T) { t.Parallel() - ctx := context.TODO() + ctx := t.Context() tests := []struct { name string diff --git a/internal/rbd/snapshot_test.go b/internal/rbd/snapshot_test.go index 0ce21b1fa..abd134627 100644 --- a/internal/rbd/snapshot_test.go +++ b/internal/rbd/snapshot_test.go @@ -17,7 +17,6 @@ limitations under the License. package rbd import ( - "context" "testing" "time" ) @@ -78,7 +77,7 @@ func TestToCSISnapshot(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { t.Parallel() - if _, err := tt.rs.ToCSI(context.TODO()); (err != nil) != tt.wantErr { + if _, err := tt.rs.ToCSI(t.Context()); (err != nil) != tt.wantErr { t.Errorf("ToCSI() error = %v, wantErr %v", err, tt.wantErr) } }) diff --git a/internal/util/cephcmds_test.go b/internal/util/cephcmds_test.go index b8ef4a0d7..b79fef3ba 100644 --- a/internal/util/cephcmds_test.go +++ b/internal/util/cephcmds_test.go @@ -41,7 +41,7 @@ func TestExecCommandWithTimeout(t *testing.T) { { name: "echo hello", args: args{ - ctx: context.TODO(), + ctx: t.Context(), program: "echo", timeout: time.Second, args: []string{"hello"}, @@ -53,7 +53,7 @@ func TestExecCommandWithTimeout(t *testing.T) { { name: "sleep with timeout", args: args{ - ctx: context.TODO(), + ctx: t.Context(), program: "sleep", timeout: time.Second, args: []string{"3"}, diff --git a/internal/util/cluster_mapping_test.go b/internal/util/cluster_mapping_test.go index 0fecf89fe..1763b09e5 100644 --- a/internal/util/cluster_mapping_test.go +++ b/internal/util/cluster_mapping_test.go @@ -295,7 +295,7 @@ func TestGetMappedID(t *testing.T) { func TestFetchMappedClusterIDAndMons(t *testing.T) { t.Parallel() - ctx := context.TODO() + ctx := t.Context() type args struct { ctx context.Context clusterID string diff --git a/internal/util/crypto_test.go b/internal/util/crypto_test.go index adf46ac6a..778aab79c 100644 --- a/internal/util/crypto_test.go +++ b/internal/util/crypto_test.go @@ -17,7 +17,6 @@ limitations under the License. package util import ( - "context" "encoding/base64" "testing" @@ -56,7 +55,7 @@ func TestKMSWorkflow(t *testing.T) { require.Equal(t, kms.DefaultKMSType, ve.GetID()) volumeID := "volume-id" - ctx := context.TODO() + ctx := t.Context() err = ve.StoreNewCryptoPassphrase(ctx, volumeID, defaultEncryptionPassphraseSize) require.NoError(t, err) diff --git a/internal/util/getsecret_test.go b/internal/util/getsecret_test.go index 71e54ddd0..bc30034b1 100644 --- a/internal/util/getsecret_test.go +++ b/internal/util/getsecret_test.go @@ -14,7 +14,6 @@ limitations under the License. package util import ( - "context" "errors" "testing" @@ -35,7 +34,7 @@ func TestGetPassphraseFromKMS(t *testing.T) { volEnc, err := NewVolumeEncryption(provider.UniqueID, kms) if errors.Is(err, ErrDEKStoreNeeded) { - _, err = volEnc.KMS.GetSecret(context.TODO(), "") + _, err = volEnc.KMS.GetSecret(t.Context(), "") if errors.Is(err, kmsapi.ErrGetSecretUnsupported) { continue // currently unsupported by fscrypt integration } @@ -46,7 +45,7 @@ func TestGetPassphraseFromKMS(t *testing.T) { continue } - secret, err := kms.GetSecret(context.TODO(), "") + secret, err := kms.GetSecret(t.Context(), "") require.NoError(t, err, provider.UniqueID) require.NotEmpty(t, secret, provider.UniqueID) }