mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +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
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user