build: address 'copyloopvar' linter warning

golangci-lint reports these:

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

Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
Niels de Vos 2024-04-26 10:35:01 +02:00 committed by mergify[bot]
parent 9321fe03c3
commit 0e7b06e9d0
24 changed files with 197 additions and 259 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -77,11 +77,10 @@ func TestValidateStriping(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 := validateStriping(ts.parameters); (err != nil) != ts.wantErr {
t.Errorf("validateStriping() error = %v, wantErr %v", err, ts.wantErr)
if err := validateStriping(tt.parameters); (err != nil) != tt.wantErr {
t.Errorf("validateStriping() error = %v, wantErr %v", err, tt.wantErr)
}
})
}

View File

@ -76,23 +76,22 @@ func TestParseEncryptionOpts(t *testing.T) {
}
for _, tt := range tests {
newtt := tt
t.Run(newtt.testName, func(t *testing.T) {
t.Run(tt.testName, func(t *testing.T) {
t.Parallel()
actualKMS, actualEnc, actualErr := ParseEncryptionOpts(
newtt.volOptions,
newtt.fallbackType,
tt.volOptions,
tt.fallbackType,
)
if actualKMS != newtt.expectedKMS {
t.Errorf("Expected KMS ID: %s, but got: %s", newtt.expectedKMS, actualKMS)
if actualKMS != tt.expectedKMS {
t.Errorf("Expected KMS ID: %s, but got: %s", tt.expectedKMS, actualKMS)
}
if actualEnc != newtt.expectedEnc {
t.Errorf("Expected Encryption Type: %v, but got: %v", newtt.expectedEnc, actualEnc)
if actualEnc != tt.expectedEnc {
t.Errorf("Expected Encryption Type: %v, but got: %v", tt.expectedEnc, actualEnc)
}
if (actualErr != nil) != newtt.expectedErr {
t.Errorf("expected error %v but got %v", newtt.expectedErr, actualErr)
if (actualErr != nil) != tt.expectedErr {
t.Errorf("expected error %v but got %v", tt.expectedErr, actualErr)
}
})
}

View File

@ -54,12 +54,11 @@ func TestIsMigrationVolID(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()
got := isMigrationVolID(newtt.args)
if got != newtt.migVolID {
t.Errorf("isMigrationVolID() = %v, want %v", got, newtt.migVolID)
got := isMigrationVolID(tt.args)
if got != tt.migVolID {
t.Errorf("isMigrationVolID() = %v, want %v", got, tt.migVolID)
}
})
}
@ -156,17 +155,16 @@ func TestParseMigrationVolID(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()
got, err := parseMigrationVolID(newtt.args)
if (err != nil) != newtt.wantErr {
t.Errorf("ParseMigrationVolID() error = %v, wantErr %v", err, newtt.wantErr)
got, err := parseMigrationVolID(tt.args)
if (err != nil) != tt.wantErr {
t.Errorf("ParseMigrationVolID() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, newtt.want) {
t.Errorf("ParseMigrationVolID() got = %v, want %v", got, newtt.want)
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("ParseMigrationVolID() got = %v, want %v", got, tt.want)
}
})
}

View File

@ -104,11 +104,10 @@ func TestParseBoolOption(t *testing.T) {
}
for _, tt := range tests {
tc := tt
val := parseBoolOption(ctx, tc.scParameters, optionName, defaultValue)
if val != tc.expect {
val := parseBoolOption(ctx, tt.scParameters, optionName, defaultValue)
if val != tt.expect {
t.Errorf("parseBoolOption(%v) returned: %t, expected: %t",
tc.scParameters, val, tc.expect)
tt.scParameters, val, tt.expect)
}
}
}
@ -188,15 +187,14 @@ func TestNodeServer_appendReadAffinityMapOptions(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()
rv := &rbdVolume{
MapOptions: currentTT.args.mapOptions,
Mounter: currentTT.args.mounter,
MapOptions: tt.args.mapOptions,
Mounter: tt.args.mounter,
}
rv.appendReadAffinityMapOptions(currentTT.args.readAffinityMapOptions)
require.Equal(t, currentTT.want, rv.MapOptions)
rv.appendReadAffinityMapOptions(tt.args.readAffinityMapOptions)
require.Equal(t, tt.want, rv.MapOptions)
})
}
}
@ -294,10 +292,9 @@ func TestReadAffinity_GetReadAffinityMapOptions(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()
crushLocationMap := util.GetCrushLocationMap(tc.CLICrushLocationLabels, nodeLabels)
crushLocationMap := util.GetCrushLocationMap(tt.CLICrushLocationLabels, nodeLabels)
cliReadAffinityMapOptions := util.ConstructReadAffinityMapOption(crushLocationMap)
driver := &csicommon.CSIDriver{}
@ -307,13 +304,13 @@ func TestReadAffinity_GetReadAffinityMapOptions(t *testing.T) {
),
}
readAffinityMapOptions, err := util.GetReadAffinityMapOptions(
tmpConfPath, tc.clusterID, ns.CLIReadAffinityOptions, nodeLabels,
tmpConfPath, tt.clusterID, ns.CLIReadAffinityOptions, nodeLabels,
)
if err != nil {
require.Fail(t, err.Error())
}
require.Equal(t, tc.want, readAffinityMapOptions)
require.Equal(t, tt.want, readAffinityMapOptions)
})
}
}

View File

@ -82,24 +82,23 @@ func TestParseMapOptions(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()
krbdOpts, nbdOpts, err := parseMapOptions(tc.mapOption)
if err != nil && !strings.Contains(err.Error(), tc.expectErr) {
krbdOpts, nbdOpts, err := parseMapOptions(tt.mapOption)
if err != nil && !strings.Contains(err.Error(), tt.expectErr) {
// returned error
t.Errorf("parseMapOptions(%s) returned error, expected: %v, got: %v",
tc.mapOption, tc.expectErr, err)
tt.mapOption, tt.expectErr, err)
}
if krbdOpts != tc.expectKrbdOptions {
if krbdOpts != tt.expectKrbdOptions {
// unexpected krbd option error
t.Errorf("parseMapOptions(%s) returned unexpected krbd options, expected :%q, got: %q",
tc.mapOption, tc.expectKrbdOptions, krbdOpts)
tt.mapOption, tt.expectKrbdOptions, krbdOpts)
}
if nbdOpts != tc.expectNbdOptions {
if nbdOpts != tt.expectNbdOptions {
// unexpected nbd option error
t.Errorf("parseMapOptions(%s) returned unexpected nbd options, expected: %q, got: %q",
tc.mapOption, tc.expectNbdOptions, nbdOpts)
tt.mapOption, tt.expectNbdOptions, nbdOpts)
}
})
}

View File

@ -233,7 +233,6 @@ func TestGetCephClientLogFileName(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
val := getCephClientLogFileName(tt.args.id, tt.args.logDir, tt.args.prefix)
@ -289,7 +288,6 @@ func TestStrategicActionOnLogFile(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
strategicActionOnLogFile(ctx, tt.args.logStrategy, tt.args.logFile)
@ -337,8 +335,7 @@ func TestIsKrbdFeatureSupported(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()
var err error
krbdSupportedFeaturesAttr := "0x1"
@ -349,12 +346,12 @@ func TestIsKrbdFeatureSupported(t *testing.T) {
// In case /sys/bus/rbd/supported_features is absent and we are
// not in a position to prepare krbd feature attributes,
// isKrbdFeatureSupported returns error ErrNotExist
supported, err := isKrbdFeatureSupported(ctx, tc.featureName)
supported, err := isKrbdFeatureSupported(ctx, tt.featureName)
if err != nil && !errors.Is(err, os.ErrNotExist) {
t.Errorf("isKrbdFeatureSupported(%s) returned error: %v", tc.featureName, err)
} else if supported != tc.isSupported {
t.Errorf("isKrbdFeatureSupported(%s) returned error: %v", tt.featureName, err)
} else if supported != tt.isSupported {
t.Errorf("isKrbdFeatureSupported(%s) returned supported status, expected: %t, got: %t",
tc.featureName, tc.isSupported, supported)
tt.featureName, tt.isSupported, supported)
}
})
}
@ -382,11 +379,10 @@ func Test_checkValidImageFeatures(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()
if got := checkValidImageFeatures(tc.imageFeatures, tc.ok); got != tc.want {
t.Errorf("checkValidImageFeatures() = %v, want %v", got, tc.want)
if got := checkValidImageFeatures(tt.imageFeatures, tt.ok); got != tt.want {
t.Errorf("checkValidImageFeatures() = %v, want %v", got, tt.want)
}
})
}

View File

@ -64,25 +64,24 @@ func TestExecCommandWithTimeout(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()
stdout, _, err := ExecCommandWithTimeout(newtt.args.ctx,
newtt.args.timeout,
newtt.args.program,
newtt.args.args...)
if (err != nil) != newtt.wantErr {
t.Errorf("ExecCommandWithTimeout() error = %v, wantErr %v", err, newtt.wantErr)
stdout, _, err := ExecCommandWithTimeout(tt.args.ctx,
tt.args.timeout,
tt.args.program,
tt.args.args...)
if (err != nil) != tt.wantErr {
t.Errorf("ExecCommandWithTimeout() error = %v, wantErr %v", err, tt.wantErr)
return
}
if newtt.wantErr && !errors.Is(err, newtt.expectedErr) {
t.Errorf("ExecCommandWithTimeout() error expected got = %v, want %v", err, newtt.expectedErr)
if tt.wantErr && !errors.Is(err, tt.expectedErr) {
t.Errorf("ExecCommandWithTimeout() error expected got = %v, want %v", err, tt.expectedErr)
}
if stdout != newtt.stdout {
t.Errorf("ExecCommandWithTimeout() got = %v, want %v", stdout, newtt.stdout)
if stdout != tt.stdout {
t.Errorf("ExecCommandWithTimeout() got = %v, want %v", stdout, tt.stdout)
}
})
}

View File

@ -138,23 +138,21 @@ func TestGetClusterMappingInfo(t *testing.T) {
},
}
for i, tt := range tests {
currentI := i
currentTT := tt
t.Run(currentTT.name, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
mappingConfigFile := fmt.Sprintf("%s/mapping-%d.json", mappingBasePath, currentI)
if len(currentTT.mappingFilecontent) != 0 {
err = os.WriteFile(mappingConfigFile, currentTT.mappingFilecontent, 0o600)
mappingConfigFile := fmt.Sprintf("%s/mapping-%d.json", mappingBasePath, i)
if len(tt.mappingFilecontent) != 0 {
err = os.WriteFile(mappingConfigFile, tt.mappingFilecontent, 0o600)
if err != nil {
t.Errorf("failed to write to %q, error = %v", mappingConfigFile, err)
}
}
data, mErr := getClusterMappingInfo(currentTT.clusterID, mappingConfigFile)
if (mErr != nil) != currentTT.expectErr {
t.Errorf("getClusterMappingInfo() error = %v, expected Error %v", mErr, currentTT.expectErr)
data, mErr := getClusterMappingInfo(tt.clusterID, mappingConfigFile)
if (mErr != nil) != tt.expectErr {
t.Errorf("getClusterMappingInfo() error = %v, expected Error %v", mErr, tt.expectErr)
}
if !reflect.DeepEqual(data, currentTT.expectedData) {
t.Errorf("getClusterMappingInfo() = %v, expected data %v", data, currentTT.expectedData)
if !reflect.DeepEqual(data, tt.expectedData) {
t.Errorf("getClusterMappingInfo() = %v, expected data %v", data, tt.expectedData)
}
})
}
@ -285,7 +283,6 @@ func TestGetMappedID(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
val := GetMappedID(tt.args.key, tt.args.value, tt.args.id)
@ -407,7 +404,6 @@ func TestFetchMappedClusterIDAndMons(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, got1, err := fetchMappedClusterIDAndMons(ctx, tt.args.clusterID, clusterMappingConfigFile, csiConfigFile)

View File

@ -39,11 +39,10 @@ func TestIsMigrationSecret(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()
if got := isMigrationSecret(newtt.vc); got != newtt.want {
t.Errorf("isMigrationSecret() = %v, want %v", got, newtt.want)
if got := isMigrationSecret(tt.vc); got != tt.want {
t.Errorf("isMigrationSecret() = %v, want %v", got, tt.want)
}
})
}
@ -83,17 +82,16 @@ func TestParseAndSetSecretMapFromMigSecret(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()
got, err := ParseAndSetSecretMapFromMigSecret(newtt.secretmap)
if (err != nil) != newtt.wantErr {
t.Errorf("ParseAndSetSecretMapFromMigSecret() error = %v, wantErr %v", err, newtt.wantErr)
got, err := ParseAndSetSecretMapFromMigSecret(tt.secretmap)
if (err != nil) != tt.wantErr {
t.Errorf("ParseAndSetSecretMapFromMigSecret() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, newtt.want) {
t.Errorf("ParseAndSetSecretMapFromMigSecret() got = %v, want %v", got, newtt.want)
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("ParseAndSetSecretMapFromMigSecret() got = %v, want %v", got, tt.want)
}
})
}

View File

@ -102,12 +102,11 @@ func Test_getCrushLocationMap(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()
require.Equal(t,
currentTT.want,
getCrushLocationMap(currentTT.args.crushLocationLabels, currentTT.args.nodeLabels))
tt.want,
getCrushLocationMap(tt.args.crushLocationLabels, tt.args.nodeLabels))
})
}
}

View File

@ -199,17 +199,16 @@ func TestGetRBDNetNamespaceFilePath(t *testing.T) {
t.Errorf("failed to write %s file content: %v", CsiConfigFile, err)
}
for _, tt := range tests {
ts := tt
t.Run(ts.name, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, err := GetRBDNetNamespaceFilePath(tmpConfPath, ts.clusterID)
got, err := GetRBDNetNamespaceFilePath(tmpConfPath, tt.clusterID)
if err != nil {
t.Errorf("GetRBDNetNamespaceFilePath() error = %v", err)
return
}
if got != ts.want {
t.Errorf("GetRBDNetNamespaceFilePath() = %v, want %v", got, ts.want)
if got != tt.want {
t.Errorf("GetRBDNetNamespaceFilePath() = %v, want %v", got, tt.want)
}
})
}
@ -269,17 +268,16 @@ func TestGetCephFSNetNamespaceFilePath(t *testing.T) {
t.Errorf("failed to write %s file content: %v", CsiConfigFile, err)
}
for _, tt := range tests {
ts := tt
t.Run(ts.name, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, err := GetCephFSNetNamespaceFilePath(tmpConfPath, ts.clusterID)
got, err := GetCephFSNetNamespaceFilePath(tmpConfPath, tt.clusterID)
if err != nil {
t.Errorf("GetCephFSNetNamespaceFilePath() error = %v", err)
return
}
if got != ts.want {
t.Errorf("GetCephFSNetNamespaceFilePath() = %v, want %v", got, ts.want)
if got != tt.want {
t.Errorf("GetCephFSNetNamespaceFilePath() = %v, want %v", got, tt.want)
}
})
}
@ -339,17 +337,16 @@ func TestGetNFSNetNamespaceFilePath(t *testing.T) {
t.Errorf("failed to write %s file content: %v", CsiConfigFile, err)
}
for _, tt := range tests {
ts := tt
t.Run(ts.name, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, err := GetNFSNetNamespaceFilePath(tmpConfPath, ts.clusterID)
got, err := GetNFSNetNamespaceFilePath(tmpConfPath, tt.clusterID)
if err != nil {
t.Errorf("GetNFSNetNamespaceFilePath() error = %v", err)
return
}
if got != ts.want {
t.Errorf("GetNFSNetNamespaceFilePath() = %v, want %v", got, ts.want)
if got != tt.want {
t.Errorf("GetNFSNetNamespaceFilePath() = %v, want %v", got, tt.want)
}
})
}
@ -443,17 +440,16 @@ func TestGetReadAffinityOptions(t *testing.T) {
t.Errorf("failed to write %s file content: %v", CsiConfigFile, err)
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
enabled, labels, err := GetCrushLocationLabels(tmpConfPath, tc.clusterID)
enabled, labels, err := GetCrushLocationLabels(tmpConfPath, tt.clusterID)
if err != nil {
t.Errorf("GetCrushLocationLabels() error = %v", err)
return
}
if enabled != tc.want.enabled || labels != tc.want.labels {
t.Errorf("GetCrushLocationLabels() = {%v %v} want %v", enabled, labels, tc.want)
if enabled != tt.want.enabled || labels != tt.want.labels {
t.Errorf("GetCrushLocationLabels() = {%v %v} want %v", enabled, labels, tt.want)
}
})
}
@ -518,16 +514,15 @@ func TestGetCephFSMountOptions(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()
kernelMntOptions, fuseMntOptions, err := GetCephFSMountOptions(tmpConfPath, tc.clusterID)
kernelMntOptions, fuseMntOptions, err := GetCephFSMountOptions(tmpConfPath, tt.clusterID)
if err != nil {
t.Errorf("GetCephFSMountOptions() error = %v", err)
}
if kernelMntOptions != tc.wantKernelMntOptions || fuseMntOptions != tc.wantFuseMntOptions {
if kernelMntOptions != tt.wantKernelMntOptions || fuseMntOptions != tt.wantFuseMntOptions {
t.Errorf("GetCephFSMountOptions() = (%v, %v), want (%v, %v)",
kernelMntOptions, fuseMntOptions, tc.wantKernelMntOptions, tc.wantFuseMntOptions,
kernelMntOptions, fuseMntOptions, tt.wantKernelMntOptions, tt.wantFuseMntOptions,
)
}
})
@ -588,18 +583,17 @@ func TestGetRBDMirrorDaemonCount(t *testing.T) {
t.Errorf("failed to write %s file content: %v", CsiConfigFile, err)
}
for _, tt := range tests {
ts := tt
t.Run(ts.name, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
var got int
got, err = GetRBDMirrorDaemonCount(tmpConfPath, ts.clusterID)
got, err = GetRBDMirrorDaemonCount(tmpConfPath, tt.clusterID)
if err != nil {
t.Errorf("GetRBDMirrorDaemonCount() error = %v", err)
return
}
if got != ts.want {
t.Errorf("GetRBDMirrorDaemonCount() = %v, want %v", got, ts.want)
if got != tt.want {
t.Errorf("GetRBDMirrorDaemonCount() = %v, want %v", got, tt.want)
}
})
}

View File

@ -50,12 +50,11 @@ func TestRemoveCSIPrefixedParameters(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()
got := RemoveCSIPrefixedParameters(ts.param)
if !reflect.DeepEqual(got, ts.want) {
t.Errorf("RemoveCSIPrefixedParameters() = %v, want %v", got, ts.want)
got := RemoveCSIPrefixedParameters(tt.param)
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("RemoveCSIPrefixedParameters() = %v, want %v", got, tt.want)
}
})
}
@ -84,11 +83,10 @@ func TestGetOwner(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 got := GetOwner(ts.args); got != ts.want {
t.Errorf("GetOwner() = %v, want %v", got, ts.want)
if got := GetOwner(tt.args); got != tt.want {
t.Errorf("GetOwner() = %v, want %v", got, tt.want)
}
})
}

View File

@ -59,10 +59,9 @@ func TestReadAffinity_ConstructReadAffinityMapOption(t *testing.T) {
},
}
for _, tt := range tests {
currentTT := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
require.Contains(t, currentTT.wantAny, ConstructReadAffinityMapOption(currentTT.crushLocationmap))
require.Contains(t, tt.wantAny, ConstructReadAffinityMapOption(tt.crushLocationmap))
})
}
}

View File

@ -74,11 +74,10 @@ func TestRoundOffBytes(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 got := RoundOffBytes(ts.args.bytes); got != ts.want {
t.Errorf("RoundOffBytes() = %v, want %v", got, ts.want)
if got := RoundOffBytes(tt.args.bytes); got != tt.want {
t.Errorf("RoundOffBytes() = %v, want %v", got, tt.want)
}
})
}
@ -138,11 +137,10 @@ func TestRoundOffVolSize(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 got := RoundOffVolSize(ts.args.size); got != ts.want {
t.Errorf("RoundOffVolSize() = %v, want %v", got, ts.want)
if got := RoundOffVolSize(tt.args.size); got != tt.want {
t.Errorf("RoundOffVolSize() = %v, want %v", got, tt.want)
}
})
}
@ -233,13 +231,11 @@ func TestMountOptionsAdd(t *testing.T) {
}
for _, moaTest := range moaTests {
mt := moaTest
moaTest := moaTest
t.Run(moaTest.name, func(t *testing.T) {
t.Parallel()
result := MountOptionsAdd(mt.mountOptions, mt.option...)
if result != mt.result {
t.Errorf("MountOptionsAdd(): %v, want %v", result, mt.result)
result := MountOptionsAdd(moaTest.mountOptions, moaTest.option...)
if result != moaTest.result {
t.Errorf("MountOptionsAdd(): %v, want %v", result, moaTest.result)
}
})
}
@ -402,11 +398,10 @@ func TestRoundOffCephFSVolSize(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 got := RoundOffCephFSVolSize(ts.size); got != ts.want {
t.Errorf("RoundOffCephFSVolSize() = %v, want %v", got, ts.want)
if got := RoundOffCephFSVolSize(tt.size); got != tt.want {
t.Errorf("RoundOffCephFSVolSize() = %v, want %v", got, tt.want)
}
})
}