Skip to content

Commit

Permalink
build: address 'copyloopvar' linter warning
Browse files Browse the repository at this point in the history
golangci-lint reports these:

    The copy of the 'for' variable "kmsID" can be deleted (Go 1.22+)
    (copyloopvar)

Signed-off-by: Niels de Vos <[email protected]>
  • Loading branch information
nixpanic committed Apr 29, 2024
1 parent af61009 commit 0fc86df
Show file tree
Hide file tree
Showing 24 changed files with 197 additions and 259 deletions.
5 changes: 0 additions & 5 deletions e2e/cephfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,6 @@ var _ = Describe(cephfsType, func() {
}

for kmsID, kmsConf := range kmsToTest {
kmsID := kmsID
kmsConf := kmsConf
By("create a storageclass with pool and an encrypted PVC then bind it to an app with "+kmsID, func() {
scOpts := map[string]string{
"encrypted": "true",
Expand Down Expand Up @@ -1649,7 +1647,6 @@ var _ = Describe(cephfsType, func() {

if testCephFSFscrypt {
for _, kmsID := range []string{"secrets-metadata-test", "vault-test"} {
kmsID := kmsID
By("checking encrypted snapshot-backed volume with KMS "+kmsID, func() {
err := deleteResource(cephFSExamplePath + "storageclass.yaml")
if err != nil {
Expand Down Expand Up @@ -2234,8 +2231,6 @@ var _ = Describe(cephfsType, func() {
"vault-test": vaultKMS,
}
for kmsID, kmsConf := range kmsToTest {
kmsID := kmsID
kmsConf := kmsConf
By("create an encrypted PVC-PVC clone and bind it to an app with "+kmsID, func() {
err := deleteResource(cephFSExamplePath + "storageclass.yaml")
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion e2e/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ Error from server (AlreadyExists): error when creating "STDIN": deployments.apps
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := getStdErr(tt.errString); got != tt.expected {
Expand Down
9 changes: 4 additions & 5 deletions internal/cephfs/groupcontrollerserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,12 @@ func TestControllerServer_validateCreateVolumeGroupSnapshotRequest(t *testing.T)
},
}
for _, tt := range tests {
ts := tt
t.Run(ts.name, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := cs.validateCreateVolumeGroupSnapshotRequest(ts.args.ctx, ts.args.req)
if ts.wantErr {
err := cs.validateCreateVolumeGroupSnapshotRequest(tt.args.ctx, tt.args.req)
if tt.wantErr {
c := status.Code(err)
if c != ts.code {
if c != tt.code {
t.Errorf("ControllerServer.validateVolumeGroupSnapshotRequest() error = %v, want code %v", err, c)
}
}
Expand Down
17 changes: 8 additions & 9 deletions internal/cephfs/nodeserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,28 +143,27 @@ func Test_setMountOptions(t *testing.T) {
}

for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

driver := &csicommon.CSIDriver{}
tc.ns.DefaultNodeServer = csicommon.NewDefaultNodeServer(
tt.ns.DefaultNodeServer = csicommon.NewDefaultNodeServer(
driver, "cephfs", "", map[string]string{}, map[string]string{},
)

err := tc.ns.setMountOptions(tc.mnt, tc.volOptions, volCap, tmpConfPath)
err := tt.ns.setMountOptions(tt.mnt, tt.volOptions, volCap, tmpConfPath)
if err != nil {
t.Errorf("setMountOptions() = %v", err)
}

switch tc.mnt.(type) {
switch tt.mnt.(type) {
case *mounter.FuseMounter:
if !strings.Contains(tc.volOptions.FuseMountOptions, tc.want) {
t.Errorf("Set FuseMountOptions = %v Required FuseMountOptions = %v", tc.volOptions.FuseMountOptions, tc.want)
if !strings.Contains(tt.volOptions.FuseMountOptions, tt.want) {
t.Errorf("Set FuseMountOptions = %v Required FuseMountOptions = %v", tt.volOptions.FuseMountOptions, tt.want)
}
case mounter.KernelMounter:
if !strings.Contains(tc.volOptions.KernelMountOptions, tc.want) {
t.Errorf("Set KernelMountOptions = %v Required KernelMountOptions = %v", tc.volOptions.KernelMountOptions, tc.want)
if !strings.Contains(tt.volOptions.KernelMountOptions, tt.want) {
t.Errorf("Set KernelMountOptions = %v Required KernelMountOptions = %v", tt.volOptions.KernelMountOptions, tt.want)
}
}
})
Expand Down
20 changes: 9 additions & 11 deletions internal/cephfs/store/volumeoptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,11 @@ func TestIsVolumeCreateRO(t *testing.T) {
},
}
for _, tt := range tests {
newtt := tt
t.Run(newtt.name, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
wantErr := IsVolumeCreateRO(newtt.caps)
if wantErr != newtt.isRO {
t.Errorf("isVolumeCreateRO() wantErr = %v, isRO %v", wantErr, newtt.isRO)
wantErr := IsVolumeCreateRO(tt.caps)
if wantErr != tt.isRO {
t.Errorf("isVolumeCreateRO() wantErr = %v, isRO %v", wantErr, tt.isRO)
}
})
}
Expand Down Expand Up @@ -209,13 +208,12 @@ func TestIsShallowVolumeSupported(t *testing.T) {
},
}
for _, tt := range tests {
newtt := tt
t.Run(newtt.name, func(t *testing.T) {
t.Log(newtt.args.req.GetVolumeContentSource().GetSnapshot())
t.Log(IsVolumeCreateRO(newtt.args.req.GetVolumeCapabilities()))
t.Run(tt.name, func(t *testing.T) {
t.Log(tt.args.req.GetVolumeContentSource().GetSnapshot())
t.Log(IsVolumeCreateRO(tt.args.req.GetVolumeCapabilities()))
t.Parallel()
if got := IsShallowVolumeSupported(newtt.args.req); got != newtt.want {
t.Errorf("IsShallowVolumeSupported() = %v, want %v", got, newtt.want)
if got := IsShallowVolumeSupported(tt.args.req); got != tt.want {
t.Errorf("IsShallowVolumeSupported() = %v, want %v", got, tt.want)
}
})
}
Expand Down
34 changes: 15 additions & 19 deletions internal/csi-addons/networkfence/fencing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ func TestGetIPRange(t *testing.T) {
},
}
for _, tt := range tests {
ts := tt
t.Run(ts.cidr, func(t *testing.T) {
t.Run(tt.cidr, func(t *testing.T) {
t.Parallel()
got, err := getIPRange(ts.cidr)
got, err := getIPRange(tt.cidr)
require.NoError(t, err)

// validate if number of IPs in the range is same as expected, if not, fail.
require.ElementsMatch(t, ts.expectedIPs, got)
require.ElementsMatch(t, tt.expectedIPs, got)
})
}
}
Expand Down Expand Up @@ -86,20 +85,18 @@ func TestFetchIP(t *testing.T) {
}

for _, tt := range tests {
ts := tt

t.Run(ts.clientInfo, func(t *testing.T) {
t.Run(tt.clientInfo, func(t *testing.T) {
t.Parallel()

client := activeClient{Inst: ts.clientInfo}
client := activeClient{Inst: tt.clientInfo}
ip, actualErr := client.fetchIP()

if (actualErr != nil) != ts.expectedErr {
t.Errorf("expected error %v but got %v", ts.expectedErr, actualErr)
if (actualErr != nil) != tt.expectedErr {
t.Errorf("expected error %v but got %v", tt.expectedErr, actualErr)
}

if ip != ts.expectedIP {
t.Errorf("expected IP %s but got %s", ts.expectedIP, ip)
if ip != tt.expectedIP {
t.Errorf("expected IP %s but got %s", tt.expectedIP, ip)
}
})
}
Expand All @@ -126,18 +123,17 @@ func TestFetchID(t *testing.T) {
}

for _, tt := range tests {
ts := tt
t.Run(ts.clientInfo, func(t *testing.T) {
t.Run(tt.clientInfo, func(t *testing.T) {
t.Parallel()
ac := &activeClient{Inst: ts.clientInfo}
ac := &activeClient{Inst: tt.clientInfo}
actualID, actualErr := ac.fetchID()

if (actualErr != nil) != ts.expectedErr {
t.Errorf("expected error %v but got %v", ts.expectedErr, actualErr)
if (actualErr != nil) != tt.expectedErr {
t.Errorf("expected error %v but got %v", tt.expectedErr, actualErr)
}

if actualID != ts.expectedID {
t.Errorf("expected ID %d but got %d", ts.expectedID, actualID)
if actualID != tt.expectedID {
t.Errorf("expected ID %d but got %d", tt.expectedID, actualID)
}
})
}
Expand Down
20 changes: 6 additions & 14 deletions internal/csi-addons/rbd/replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func TestValidateSchedulingInterval(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := validateSchedulingInterval(tt.interval)
Expand Down Expand Up @@ -147,7 +146,6 @@ func TestValidateSchedulingDetails(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := validateSchedulingDetails(ctx, tt.parameters)
Expand Down Expand Up @@ -203,7 +201,6 @@ func TestGetSchedulingDetails(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
interval, startTime := getSchedulingDetails(tt.parameters)
Expand Down Expand Up @@ -251,11 +248,10 @@ func TestCheckVolumeResyncStatus(t *testing.T) {
},
}
for _, tt := range tests {
ts := tt
t.Run(ts.name, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if err := checkVolumeResyncStatus(ctx, ts.args); (err != nil) != ts.wantErr {
t.Errorf("checkVolumeResyncStatus() error = %v, expect error = %v", err, ts.wantErr)
if err := checkVolumeResyncStatus(ctx, tt.args); (err != nil) != tt.wantErr {
t.Errorf("checkVolumeResyncStatus() error = %v, expect error = %v", err, tt.wantErr)
}
})
}
Expand Down Expand Up @@ -388,11 +384,10 @@ func TestCheckRemoteSiteStatus(t *testing.T) {
},
}
for _, tt := range tests {
ts := tt
t.Run(ts.name, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if ready := checkRemoteSiteStatus(context.TODO(), &ts.args); ready != ts.wantReady {
t.Errorf("checkRemoteSiteStatus() ready = %v, expect ready = %v", ready, ts.wantReady)
if ready := checkRemoteSiteStatus(context.TODO(), &tt.args); ready != tt.wantReady {
t.Errorf("checkRemoteSiteStatus() ready = %v, expect ready = %v", ready, tt.wantReady)
}
})
}
Expand Down Expand Up @@ -501,7 +496,6 @@ func TestValidateLastSyncInfo(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
teststruct, err := getLastSyncInfo(ctx, tt.description)
Expand Down Expand Up @@ -600,7 +594,6 @@ func TestGetGRPCError(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
result := getGRPCError(tt.err)
Expand Down Expand Up @@ -656,7 +649,6 @@ func Test_timestampFromString(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, err := timestampFromString(tt.timestamp)
Expand Down
31 changes: 14 additions & 17 deletions internal/csi-common/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,11 @@ func TestIsFileRWO(t *testing.T) {
}

for _, tt := range tests {
newtt := tt
t.Run(newtt.name, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
rwoFile := IsFileRWO(newtt.caps)
if rwoFile != newtt.rwoFile {
t.Errorf("IsFileRWO() rwofile = %v, want %v", rwoFile, newtt.rwoFile)
rwoFile := IsFileRWO(tt.caps)
if rwoFile != tt.rwoFile {
t.Errorf("IsFileRWO() rwofile = %v, want %v", rwoFile, tt.rwoFile)
}
})
}
Expand Down Expand Up @@ -482,15 +481,14 @@ func TestIsBlockMultiWriter(t *testing.T) {
}

for _, tt := range tests {
newtt := tt
t.Run(newtt.name, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
multiWriter, block := IsBlockMultiWriter(newtt.caps)
if multiWriter != newtt.multiWriter {
t.Errorf("IsBlockMultiWriter() multiWriter = %v, want %v", multiWriter, newtt.multiWriter)
multiWriter, block := IsBlockMultiWriter(tt.caps)
if multiWriter != tt.multiWriter {
t.Errorf("IsBlockMultiWriter() multiWriter = %v, want %v", multiWriter, tt.multiWriter)
}
if block != newtt.block {
t.Errorf("IsBlockMultiWriter block = %v, want %v", block, newtt.block)
if block != tt.block {
t.Errorf("IsBlockMultiWriter block = %v, want %v", block, tt.block)
}
})
}
Expand Down Expand Up @@ -615,12 +613,11 @@ func TestIsReaderOnly(t *testing.T) {
}

for _, tt := range tests {
newtt := tt
t.Run(newtt.name, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
roOnly := IsReaderOnly(newtt.caps)
if roOnly != newtt.roOnly {
t.Errorf("isReadOnly() roOnly = %v, want %v", roOnly, newtt.roOnly)
roOnly := IsReaderOnly(tt.caps)
if roOnly != tt.roOnly {
t.Errorf("isReadOnly() roOnly = %v, want %v", roOnly, tt.roOnly)
}
})
}
Expand Down
11 changes: 5 additions & 6 deletions internal/kms/kms_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,14 @@ func TestSetConfigInt(t *testing.T) {
},
}
for _, tt := range tests {
currentTT := tt
t.Run(currentTT.name, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := setConfigInt(currentTT.args.option, currentTT.args.config, currentTT.args.key)
if !errors.Is(err, currentTT.err) {
t.Errorf("setConfigInt() error = %v, wantErr %v", err, currentTT.err)
err := setConfigInt(tt.args.option, tt.args.config, tt.args.key)
if !errors.Is(err, tt.err) {
t.Errorf("setConfigInt() error = %v, wantErr %v", err, tt.err)
}
if err != nil {
require.NotEqual(t, currentTT.value, currentTT.args.option)
require.NotEqual(t, tt.value, tt.args.option)
}
})
}
Expand Down
22 changes: 10 additions & 12 deletions internal/nfs/nodeserver/nodeserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,11 @@ func Test_validateNodePublishVolumeRequest(t *testing.T) {
},
}
for _, tt := range tests {
currentTT := tt
t.Run(currentTT.name, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := validateNodePublishVolumeRequest(currentTT.args.req)
if (err != nil) != currentTT.wantErr {
t.Errorf("validateNodePublishVoluemRequest() error = %v, wantErr %v", err, currentTT.wantErr)
err := validateNodePublishVolumeRequest(tt.args.req)
if (err != nil) != tt.wantErr {
t.Errorf("validateNodePublishVoluemRequest() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
Expand Down Expand Up @@ -157,17 +156,16 @@ func Test_getSource(t *testing.T) {
},
}
for _, tt := range tests {
currentTT := tt
t.Run(currentTT.name, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, err := getSource(currentTT.args.volContext)
if (err != nil) != currentTT.wantErr {
t.Errorf("getSource() error = %v, wantErr %v", err, currentTT.wantErr)
got, err := getSource(tt.args.volContext)
if (err != nil) != tt.wantErr {
t.Errorf("getSource() error = %v, wantErr %v", err, tt.wantErr)

return
}
if got != currentTT.want {
t.Errorf("getSource() = %v, want %v", got, currentTT.want)
if got != tt.want {
t.Errorf("getSource() = %v, want %v", got, tt.want)
}
})
}
Expand Down
Loading

0 comments on commit 0fc86df

Please sign in to comment.