mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
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:
committed by
mergify[bot]
parent
9321fe03c3
commit
0e7b06e9d0
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user