Skip to content

Commit 28b5101

Browse files
authored
Merge pull request #2399 from ElijahQuinones/useTesting
Enable useTesting linter
2 parents 1236c9a + 06c7bdf commit 28b5101

File tree

5 files changed

+131
-130
lines changed

5 files changed

+131
-130
lines changed

.golangci.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ linters-settings:
3737
dot-import-whitelist:
3838
- "github.com/onsi/gomega"
3939
- "github.com/onsi/ginkgo/v2"
40+
usetesting:
41+
# Turning check for os.MkdirTemp() off as t.TempDir() is not sufficient for mounter and sanity tests in their current state.
42+
os-mkdir-temp: false
4043
linters:
4144
enable-all: true
4245
disable:
@@ -68,4 +71,3 @@ linters:
6871
- godox # Do not allow TODOs
6972
- nonamedreturns # Need to nolint/refactor a few places our code
7073
- paralleltest # There are many tests that aren't parallelized
71-
- usetesting # TODO consider adding usetesting linter

pkg/cloud/cloud_test.go

+22-22
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ func TestCheckDesiredState(t *testing.T) {
689689
},
690690
},
691691
}, nil)
692-
_, err := cloudInstance.checkDesiredState(context.Background(), tc.volumeID, tc.desiredSizeGiB, tc.options)
692+
_, err := cloudInstance.checkDesiredState(t.Context(), tc.volumeID, tc.desiredSizeGiB, tc.options)
693693
if err != nil {
694694
if tc.expErr == nil {
695695
t.Fatalf("Did not expect to get an error but got %q", err)
@@ -1385,7 +1385,7 @@ func TestCreateDisk(t *testing.T) {
13851385
VolumeId: aws.String("snap-test-volume"),
13861386
State: types.SnapshotStateCompleted,
13871387
}
1388-
ctx, ctxCancel := context.WithDeadline(context.Background(), time.Now().Add(defaultCreateDiskDeadline))
1388+
ctx, ctxCancel := context.WithDeadline(t.Context(), time.Now().Add(defaultCreateDiskDeadline))
13891389
defer ctxCancel()
13901390

13911391
if tc.expCreateVolumeInput != nil {
@@ -1506,7 +1506,7 @@ func TestCreateDiskClientToken(t *testing.T) {
15061506
}, nil).AnyTimes(),
15071507
)
15081508

1509-
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(defaultCreateDiskDeadline))
1509+
ctx, cancel := context.WithDeadline(t.Context(), time.Now().Add(defaultCreateDiskDeadline))
15101510
defer cancel()
15111511
for i := range 3 {
15121512
_, err := c.CreateDisk(ctx, volumeName, diskOptions)
@@ -1551,7 +1551,7 @@ func TestDeleteDisk(t *testing.T) {
15511551
mockEC2 := NewMockEC2API(mockCtrl)
15521552
c := newCloud(mockEC2)
15531553

1554-
ctx := context.Background()
1554+
ctx := t.Context()
15551555
mockEC2.EXPECT().DeleteVolume(gomock.Any(), gomock.Any(), gomock.Any()).Return(&ec2.DeleteVolumeOutput{}, tc.expErr)
15561556

15571557
ok, err := c.DeleteDisk(ctx, tc.volumeID)
@@ -1759,7 +1759,7 @@ func TestAttachDisk(t *testing.T) {
17591759
t.Fatalf("could not assert c as type cloud, %v", c)
17601760
}
17611761

1762-
ctx := context.Background()
1762+
ctx := t.Context()
17631763
deviceManager := cloudInstance.dm
17641764

17651765
tc.mockFunc(mockEC2, ctx, tc.volumeID, tc.nodeID, tc.nodeID2, tc.path, deviceManager)
@@ -1848,7 +1848,7 @@ func TestDetachDisk(t *testing.T) {
18481848
mockEC2 := NewMockEC2API(mockCtrl)
18491849
c := newCloud(mockEC2)
18501850

1851-
ctx := context.Background()
1851+
ctx := t.Context()
18521852
tc.mockFunc(mockEC2, ctx, tc.volumeID, tc.nodeID)
18531853

18541854
err := c.DetachDisk(ctx, tc.volumeID, tc.nodeID)
@@ -1916,7 +1916,7 @@ func TestGetDiskByName(t *testing.T) {
19161916
},
19171917
}
19181918

1919-
ctx := context.Background()
1919+
ctx := t.Context()
19201920
mockEC2.EXPECT().DescribeVolumes(gomock.Any(), gomock.Any()).Return(&ec2.DescribeVolumesOutput{Volumes: []types.Volume{vol}}, tc.expErr)
19211921

19221922
disk, err := c.GetDiskByName(ctx, tc.volumeName, tc.volumeCapacity)
@@ -2010,7 +2010,7 @@ func TestGetDiskByID(t *testing.T) {
20102010
mockEC2 := NewMockEC2API(mockCtrl)
20112011
c := newCloud(mockEC2)
20122012

2013-
ctx := context.Background()
2013+
ctx := t.Context()
20142014

20152015
mockEC2.EXPECT().DescribeVolumes(gomock.Any(), gomock.Any()).Return(
20162016
&ec2.DescribeVolumesOutput{
@@ -2110,7 +2110,7 @@ func TestCreateSnapshot(t *testing.T) {
21102110
mockEC2 := NewMockEC2API(mockCtrl)
21112111
c := newCloud(mockEC2)
21122112

2113-
ctx := context.Background()
2113+
ctx := t.Context()
21142114

21152115
mockEC2.EXPECT().CreateSnapshot(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(
21162116
func(ctx context.Context, input *ec2.CreateSnapshotInput, optFns ...func(*ec2.Options)) (*ec2.CreateSnapshotOutput, error) {
@@ -2227,7 +2227,7 @@ func TestEnableFastSnapshotRestores(t *testing.T) {
22272227
mockEC2 := NewMockEC2API(mockCtrl)
22282228
c := newCloud(mockEC2)
22292229

2230-
ctx := context.Background()
2230+
ctx := t.Context()
22312231
mockEC2.EXPECT().EnableFastSnapshotRestores(gomock.Any(), gomock.Any(), gomock.Any()).Return(tc.expOutput, tc.expErr).AnyTimes()
22322232

22332233
response, err := c.EnableFastSnapshotRestores(ctx, tc.availabilityZones, tc.snapshotID)
@@ -2290,7 +2290,7 @@ func TestAvailabilityZones(t *testing.T) {
22902290
mockEC2 := NewMockEC2API(mockCtrl)
22912291
c := newCloud(mockEC2)
22922292

2293-
ctx := context.Background()
2293+
ctx := t.Context()
22942294
mockEC2.EXPECT().DescribeAvailabilityZones(gomock.Any(), gomock.Any()).Return(tc.expOutput, tc.expErr).AnyTimes()
22952295

22962296
az, err := c.AvailabilityZones(ctx)
@@ -2344,7 +2344,7 @@ func TestDeleteSnapshot(t *testing.T) {
23442344
mockEC2 := NewMockEC2API(mockCtrl)
23452345
c := newCloud(mockEC2)
23462346

2347-
ctx := context.Background()
2347+
ctx := t.Context()
23482348
mockEC2.EXPECT().DeleteSnapshot(gomock.Any(), gomock.Any(), gomock.Any()).Return(&ec2.DeleteSnapshotOutput{}, tc.expErr)
23492349

23502350
_, err := c.DeleteSnapshot(ctx, tc.snapshotName)
@@ -2633,7 +2633,7 @@ func TestResizeOrModifyDisk(t *testing.T) {
26332633
mockEC2 := NewMockEC2API(mockCtrl)
26342634
c := newCloud(mockEC2)
26352635

2636-
ctx := context.Background()
2636+
ctx := t.Context()
26372637
if tc.existingVolume != nil || tc.existingVolumeError != nil {
26382638
mockEC2.EXPECT().DescribeVolumes(gomock.Any(), gomock.Any()).Return(
26392639
&ec2.DescribeVolumesOutput{
@@ -2767,7 +2767,7 @@ func TestModifyTags(t *testing.T) {
27672767
mockEC2 := NewMockEC2API(mockCtrl)
27682768
c := newCloud(mockEC2)
27692769

2770-
ctx := context.Background()
2770+
ctx := t.Context()
27712771

27722772
if len(tc.modifyTagsOptions.TagsToAdd) > 0 {
27732773
if tc.negativeCase {
@@ -2857,7 +2857,7 @@ func TestGetSnapshotByName(t *testing.T) {
28572857
},
28582858
}
28592859

2860-
ctx := context.Background()
2860+
ctx := t.Context()
28612861

28622862
mockEC2.EXPECT().DescribeSnapshots(gomock.Any(), gomock.Any()).Return(&ec2.DescribeSnapshotsOutput{Snapshots: []types.Snapshot{ec2snapshot}}, nil)
28632863

@@ -2930,7 +2930,7 @@ func TestGetSnapshotByID(t *testing.T) {
29302930
State: types.SnapshotStateCompleted,
29312931
}
29322932

2933-
ctx := context.Background()
2933+
ctx := t.Context()
29342934

29352935
mockEC2.EXPECT().DescribeSnapshots(gomock.Any(), gomock.Any()).Return(&ec2.DescribeSnapshotsOutput{Snapshots: []types.Snapshot{ec2snapshot}}, nil)
29362936

@@ -3014,7 +3014,7 @@ func TestListSnapshots(t *testing.T) {
30143014
mockEC2 := NewMockEC2API(mockCtl)
30153015
c := newCloud(mockEC2)
30163016

3017-
ctx := context.Background()
3017+
ctx := t.Context()
30183018

30193019
mockEC2.EXPECT().DescribeSnapshots(gomock.Any(), gomock.Any()).Return(&ec2.DescribeSnapshotsOutput{Snapshots: ec2Snapshots}, nil)
30203020

@@ -3089,7 +3089,7 @@ func TestListSnapshots(t *testing.T) {
30893089
mockEC2 := NewMockEC2API(mockCtl)
30903090
c := newCloud(mockEC2)
30913091

3092-
ctx := context.Background()
3092+
ctx := t.Context()
30933093

30943094
mockEC2.EXPECT().DescribeSnapshots(gomock.Any(), gomock.Any()).Return(&ec2.DescribeSnapshotsOutput{Snapshots: ec2Snapshots}, nil)
30953095

@@ -3153,7 +3153,7 @@ func TestListSnapshots(t *testing.T) {
31533153
mockEC2 := NewMockEC2API(mockCtl)
31543154
c := newCloud(mockEC2)
31553155

3156-
ctx := context.Background()
3156+
ctx := t.Context()
31573157

31583158
firstCall := mockEC2.EXPECT().DescribeSnapshots(gomock.Any(), gomock.Any()).Return(&ec2.DescribeSnapshotsOutput{
31593159
Snapshots: ec2Snapshots[:maxResults],
@@ -3203,7 +3203,7 @@ func TestListSnapshots(t *testing.T) {
32033203
mockEC2 := NewMockEC2API(mockCtl)
32043204
c := newCloud(mockEC2)
32053205

3206-
ctx := context.Background()
3206+
ctx := t.Context()
32073207

32083208
mockEC2.EXPECT().DescribeSnapshots(gomock.Any(), gomock.Any()).Return(nil, errors.New("test error"))
32093209

@@ -3221,7 +3221,7 @@ func TestListSnapshots(t *testing.T) {
32213221
mockEC2 := NewMockEC2API(mockCtl)
32223222
c := newCloud(mockEC2)
32233223

3224-
ctx := context.Background()
3224+
ctx := t.Context()
32253225

32263226
mockEC2.EXPECT().DescribeSnapshots(gomock.Any(), gomock.Any()).Return(&ec2.DescribeSnapshotsOutput{}, nil)
32273227

@@ -3371,7 +3371,7 @@ func TestWaitForAttachmentState(t *testing.T) {
33713371
MultiAttachEnabled: aws.Bool(false),
33723372
}
33733373

3374-
ctx, cancel := context.WithCancel(context.Background())
3374+
ctx, cancel := context.WithCancel(t.Context())
33753375
defer cancel()
33763376

33773377
switch tc.name {

0 commit comments

Comments
 (0)