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

@ -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)
}
})

View File

@ -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)

View File

@ -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",

View File

@ -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

View File

@ -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",

View File

@ -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

View File

@ -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)
}
})