cleanup: addresses paralleltest linter

The Go linter paralleltest checks that the t.Parallel
gets called for the test method and for the range of
test cases within the test.

Updates: #2025

Signed-off-by: Yati Padia <ypadia@redhat.com>
This commit is contained in:
Yati Padia 2021-06-02 15:25:53 +05:30 committed by mergify[bot]
parent 0ee0c12027
commit 13667c013c
18 changed files with 41 additions and 0 deletions

View File

@ -45,6 +45,7 @@ func setDefaultKubeconfig() {
} }
func TestE2E(t *testing.T) { func TestE2E(t *testing.T) {
t.Parallel()
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "E2e Suite") RunSpecs(t, "E2e Suite")
} }

View File

@ -25,6 +25,7 @@ import (
var fakeID = "fake-id" var fakeID = "fake-id"
func TestGetReqID(t *testing.T) { func TestGetReqID(t *testing.T) {
t.Parallel()
req := []interface{}{ req := []interface{}{
&csi.CreateVolumeRequest{ &csi.CreateVolumeRequest{
Name: fakeID, Name: fakeID,

View File

@ -23,6 +23,7 @@ import (
) )
func TestGetStagingPath(t *testing.T) { func TestGetStagingPath(t *testing.T) {
t.Parallel()
var stagingPath string var stagingPath string
// test with nodestagevolumerequest // test with nodestagevolumerequest
nsvr := &csi.NodeStageVolumeRequest{ nsvr := &csi.NodeStageVolumeRequest{

View File

@ -25,6 +25,7 @@ import (
) )
func TestHasSnapshotFeature(t *testing.T) { func TestHasSnapshotFeature(t *testing.T) {
t.Parallel()
tests := []struct { tests := []struct {
features string features string
hasFeature bool hasFeature bool
@ -45,6 +46,7 @@ func TestHasSnapshotFeature(t *testing.T) {
} }
func TestValidateImageFeatures(t *testing.T) { func TestValidateImageFeatures(t *testing.T) {
t.Parallel()
tests := []struct { tests := []struct {
imageFeatures string imageFeatures string
rbdVol *rbdVolume rbdVol *rbdVolume

View File

@ -23,6 +23,7 @@ import (
) )
func TestAWSMetadataKMSRegistered(t *testing.T) { func TestAWSMetadataKMSRegistered(t *testing.T) {
t.Parallel()
_, ok := kmsManager.providers[kmsTypeAWSMetadata] _, ok := kmsManager.providers[kmsTypeAWSMetadata]
assert.True(t, ok) assert.True(t, ok)
} }

View File

@ -74,6 +74,7 @@ func (cp *ConnPool) fakeGet(monitors, user, keyfile string) (*rados.Conn, string
} }
func TestConnPool(t *testing.T) { func TestConnPool(t *testing.T) {
t.Parallel()
cp := NewConnPool(interval, expiry) cp := NewConnPool(interval, expiry)
defer cp.Destroy() defer cp.Destroy()

View File

@ -25,6 +25,7 @@ import (
) )
func TestInitSecretsKMS(t *testing.T) { func TestInitSecretsKMS(t *testing.T) {
t.Parallel()
secrets := map[string]string{} secrets := map[string]string{}
// no passphrase in the secrets, should fail // no passphrase in the secrets, should fail
@ -40,6 +41,7 @@ func TestInitSecretsKMS(t *testing.T) {
} }
func TestGenerateNewEncryptionPassphrase(t *testing.T) { func TestGenerateNewEncryptionPassphrase(t *testing.T) {
t.Parallel()
b64Passphrase, err := generateNewEncryptionPassphrase() b64Passphrase, err := generateNewEncryptionPassphrase()
require.NoError(t, err) require.NoError(t, err)
@ -51,6 +53,7 @@ func TestGenerateNewEncryptionPassphrase(t *testing.T) {
} }
func TestKMSWorkflow(t *testing.T) { func TestKMSWorkflow(t *testing.T) {
t.Parallel()
secrets := map[string]string{ secrets := map[string]string{
encryptionPassphraseKey: "workflow test", encryptionPassphraseKey: "workflow test",
} }

View File

@ -34,6 +34,7 @@ func cleanupTestData() {
// TODO: make this function less complex. // TODO: make this function less complex.
func TestCSIConfig(t *testing.T) { func TestCSIConfig(t *testing.T) {
t.Parallel()
var err error var err error
var data string var data string
var content string var content string

View File

@ -32,6 +32,7 @@ func wrapError(e error) error {
} }
func TestJoinErrors(t *testing.T) { func TestJoinErrors(t *testing.T) {
t.Parallel()
assertErrorIs := func(e1, e2 error, ok bool) { assertErrorIs := func(e1, e2 error, ok bool) {
if errors.Is(e1, e2) != ok { if errors.Is(e1, e2) != ok {
t.Errorf("errors.Is(e1, e2) != %v - e1: %#v - e2: %#v", ok, e1, e2) t.Errorf("errors.Is(e1, e2) != %v - e1: %#v - e2: %#v", ok, e1, e2)

View File

@ -22,6 +22,7 @@ import (
// very basic tests for the moment. // very basic tests for the moment.
func TestIDLocker(t *testing.T) { func TestIDLocker(t *testing.T) {
t.Parallel()
fakeID := "fake-id" fakeID := "fake-id"
locks := NewVolumeLocks() locks := NewVolumeLocks()
// acquire lock for fake-id // acquire lock for fake-id
@ -52,6 +53,7 @@ func TestIDLocker(t *testing.T) {
} }
func TestOperationLocks(t *testing.T) { func TestOperationLocks(t *testing.T) {
t.Parallel()
volumeID := "test-vol" volumeID := "test-vol"
lock := NewOperationLock() lock := NewOperationLock()
err := lock.GetCloneLock(volumeID) err := lock.GetCloneLock(volumeID)

View File

@ -27,6 +27,7 @@ func noinitKMS(args KMSInitializerArgs) (EncryptionKMS, error) {
} }
func TestRegisterKMSProvider(t *testing.T) { func TestRegisterKMSProvider(t *testing.T) {
t.Parallel()
tests := []struct { tests := []struct {
provider KMSProvider provider KMSProvider
panics bool panics bool

View File

@ -24,6 +24,7 @@ import (
// minimal test to check if GetPIDLimit() returns an int // minimal test to check if GetPIDLimit() returns an int
// changing the limit require root permissions, not tested. // changing the limit require root permissions, not tested.
func TestGetPIDLimit(t *testing.T) { func TestGetPIDLimit(t *testing.T) {
t.Parallel()
runTest := os.Getenv("CEPH_CSI_RUN_ALL_TESTS") runTest := os.Getenv("CEPH_CSI_RUN_ALL_TESTS")
if runTest == "" { if runTest == "" {
t.Skip("not running test that requires root permissions and cgroup support") t.Skip("not running test that requires root permissions and cgroup support")

View File

@ -24,6 +24,7 @@ import (
) )
func TestGenerateNonce(t *testing.T) { func TestGenerateNonce(t *testing.T) {
t.Parallel()
size := 64 size := 64
nonce, err := generateNonce(size) nonce, err := generateNonce(size)
assert.Equal(t, size, len(nonce)) assert.Equal(t, size, len(nonce))
@ -31,6 +32,7 @@ func TestGenerateNonce(t *testing.T) {
} }
func TestGenerateCipher(t *testing.T) { func TestGenerateCipher(t *testing.T) {
t.Parallel()
// nolint:gosec // this passphrase is intentionally hardcoded // nolint:gosec // this passphrase is intentionally hardcoded
passphrase := "my-cool-luks-passphrase" passphrase := "my-cool-luks-passphrase"
salt := "unique-id-for-the-volume" salt := "unique-id-for-the-volume"
@ -41,6 +43,7 @@ func TestGenerateCipher(t *testing.T) {
} }
func TestInitSecretsMetadataKMS(t *testing.T) { func TestInitSecretsMetadataKMS(t *testing.T) {
t.Parallel()
args := KMSInitializerArgs{ args := KMSInitializerArgs{
Tenant: "tenant", Tenant: "tenant",
Config: nil, Config: nil,
@ -62,6 +65,7 @@ func TestInitSecretsMetadataKMS(t *testing.T) {
} }
func TestWorkflowSecretsMetadataKMS(t *testing.T) { func TestWorkflowSecretsMetadataKMS(t *testing.T) {
t.Parallel()
secrets := map[string]string{ secrets := map[string]string{
encryptionPassphraseKey: "my-passphrase-from-kubernetes", encryptionPassphraseKey: "my-passphrase-from-kubernetes",
} }
@ -100,6 +104,7 @@ func TestWorkflowSecretsMetadataKMS(t *testing.T) {
} }
func TestSecretsMetadataKMSRegistered(t *testing.T) { func TestSecretsMetadataKMSRegistered(t *testing.T) {
t.Parallel()
_, ok := kmsManager.providers[kmsTypeSecretsMetadata] _, ok := kmsManager.providers[kmsTypeSecretsMetadata]
assert.True(t, ok) assert.True(t, ok)
} }

View File

@ -37,6 +37,7 @@ func checkAndReportError(t *testing.T, msg string, err error) {
// TestFindPoolAndTopology also tests MatchTopologyForPool. // TestFindPoolAndTopology also tests MatchTopologyForPool.
func TestFindPoolAndTopology(t *testing.T) { func TestFindPoolAndTopology(t *testing.T) {
t.Parallel()
var err error var err error
var label1 = "region" var label1 = "region"
var label2 = "zone" var label2 = "zone"

View File

@ -21,6 +21,7 @@ import (
) )
func TestRoundOffBytes(t *testing.T) { func TestRoundOffBytes(t *testing.T) {
t.Parallel()
type args struct { type args struct {
bytes int64 bytes int64
} }
@ -75,6 +76,7 @@ func TestRoundOffBytes(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
ts := tt ts := tt
t.Run(ts.name, func(t *testing.T) { t.Run(ts.name, func(t *testing.T) {
t.Parallel()
if got := RoundOffBytes(ts.args.bytes); got != ts.want { if got := RoundOffBytes(ts.args.bytes); got != ts.want {
t.Errorf("RoundOffBytes() = %v, want %v", got, ts.want) t.Errorf("RoundOffBytes() = %v, want %v", got, ts.want)
} }
@ -83,6 +85,7 @@ func TestRoundOffBytes(t *testing.T) {
} }
func TestRoundOffVolSize(t *testing.T) { func TestRoundOffVolSize(t *testing.T) {
t.Parallel()
type args struct { type args struct {
size int64 size int64
} }
@ -137,6 +140,7 @@ func TestRoundOffVolSize(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
ts := tt ts := tt
t.Run(ts.name, func(t *testing.T) { t.Run(ts.name, func(t *testing.T) {
t.Parallel()
if got := RoundOffVolSize(ts.args.size); got != ts.want { if got := RoundOffVolSize(ts.args.size); got != ts.want {
t.Errorf("RoundOffVolSize() = %v, want %v", got, ts.want) t.Errorf("RoundOffVolSize() = %v, want %v", got, ts.want)
} }
@ -145,6 +149,7 @@ func TestRoundOffVolSize(t *testing.T) {
} }
func TestGetKernelVersion(t *testing.T) { func TestGetKernelVersion(t *testing.T) {
t.Parallel()
version, err := GetKernelVersion() version, err := GetKernelVersion()
if err != nil { if err != nil {
t.Errorf("failed to get kernel version: %s", err) t.Errorf("failed to get kernel version: %s", err)
@ -158,6 +163,7 @@ func TestGetKernelVersion(t *testing.T) {
} }
func TestMountOptionsAdd(t *testing.T) { func TestMountOptionsAdd(t *testing.T) {
t.Parallel()
moaTests := []struct { moaTests := []struct {
name string name string
mountOptions string mountOptions string
@ -228,7 +234,9 @@ func TestMountOptionsAdd(t *testing.T) {
for _, moaTest := range moaTests { for _, moaTest := range moaTests {
mt := moaTest mt := moaTest
moaTest := moaTest
t.Run(moaTest.name, func(t *testing.T) { t.Run(moaTest.name, func(t *testing.T) {
t.Parallel()
result := MountOptionsAdd(mt.mountOptions, mt.option...) result := MountOptionsAdd(mt.mountOptions, mt.option...)
if result != mt.result { if result != mt.result {
t.Errorf("MountOptionsAdd(): %v, want %v", result, mt.result) t.Errorf("MountOptionsAdd(): %v, want %v", result, mt.result)
@ -237,6 +245,7 @@ func TestMountOptionsAdd(t *testing.T) {
} }
} }
func TestCheckKernelSupport(t *testing.T) { func TestCheckKernelSupport(t *testing.T) {
t.Parallel()
supportsQuota := []string{ supportsQuota := []string{
"4.17.0", "4.17.0",
"5.0.0", "5.0.0",

View File

@ -25,6 +25,7 @@ import (
) )
func TestDetectAuthMountPath(t *testing.T) { func TestDetectAuthMountPath(t *testing.T) {
t.Parallel()
authMountPath, err := detectAuthMountPath(vaultDefaultAuthPath) authMountPath, err := detectAuthMountPath(vaultDefaultAuthPath)
if err != nil { if err != nil {
t.Errorf("detectAuthMountPath() failed: %s", err) t.Errorf("detectAuthMountPath() failed: %s", err)
@ -43,6 +44,7 @@ func TestDetectAuthMountPath(t *testing.T) {
} }
func TestCreateTempFile(t *testing.T) { func TestCreateTempFile(t *testing.T) {
t.Parallel()
data := []byte("Hello World!") data := []byte("Hello World!")
tmpfile, err := createTempFile("my-file", data) tmpfile, err := createTempFile("my-file", data)
if err != nil { if err != nil {
@ -59,6 +61,7 @@ func TestCreateTempFile(t *testing.T) {
} }
func TestSetConfigString(t *testing.T) { func TestSetConfigString(t *testing.T) {
t.Parallel()
const defaultValue = "default-value" const defaultValue = "default-value"
options := make(map[string]interface{}) options := make(map[string]interface{})
@ -99,6 +102,7 @@ func TestSetConfigString(t *testing.T) {
} }
func TestVaultKMSRegistered(t *testing.T) { func TestVaultKMSRegistered(t *testing.T) {
t.Parallel()
_, ok := kmsManager.providers[kmsTypeVault] _, ok := kmsManager.providers[kmsTypeVault]
assert.True(t, ok) assert.True(t, ok)
} }

View File

@ -27,6 +27,7 @@ import (
) )
func TestParseConfig(t *testing.T) { func TestParseConfig(t *testing.T) {
t.Parallel()
kms := VaultTokensKMS{} kms := VaultTokensKMS{}
config := make(map[string]interface{}) config := make(map[string]interface{})
@ -71,6 +72,7 @@ func TestParseConfig(t *testing.T) {
// When vault.New() is called at the end of initVaultTokensKMS(), errors will // When vault.New() is called at the end of initVaultTokensKMS(), errors will
// mention the missing VAULT_TOKEN, and that is expected. // mention the missing VAULT_TOKEN, and that is expected.
func TestInitVaultTokensKMS(t *testing.T) { func TestInitVaultTokensKMS(t *testing.T) {
t.Parallel()
if true { if true {
// FIXME: testing only works when KUBE_CONFIG is set to a // FIXME: testing only works when KUBE_CONFIG is set to a
// cluster that has a working Vault deployment // cluster that has a working Vault deployment
@ -122,6 +124,7 @@ func TestInitVaultTokensKMS(t *testing.T) {
// TestStdVaultToCSIConfig converts a JSON document with standard VAULT_* // TestStdVaultToCSIConfig converts a JSON document with standard VAULT_*
// environment variables to a vaultTokenConf structure. // environment variables to a vaultTokenConf structure.
func TestStdVaultToCSIConfig(t *testing.T) { func TestStdVaultToCSIConfig(t *testing.T) {
t.Parallel()
vaultConfigMap := `{ vaultConfigMap := `{
"KMS_PROVIDER":"vaulttokens", "KMS_PROVIDER":"vaulttokens",
"VAULT_ADDR":"https://vault.example.com", "VAULT_ADDR":"https://vault.example.com",
@ -167,6 +170,7 @@ func TestStdVaultToCSIConfig(t *testing.T) {
} }
func TestTransformConfig(t *testing.T) { func TestTransformConfig(t *testing.T) {
t.Parallel()
cm := make(map[string]interface{}) cm := make(map[string]interface{})
cm["KMS_PROVIDER"] = "vaulttokens" cm["KMS_PROVIDER"] = "vaulttokens"
cm["VAULT_ADDR"] = "https://vault.example.com" cm["VAULT_ADDR"] = "https://vault.example.com"
@ -192,6 +196,7 @@ func TestTransformConfig(t *testing.T) {
} }
func TestVaultTokensKMSRegistered(t *testing.T) { func TestVaultTokensKMSRegistered(t *testing.T) {
t.Parallel()
_, ok := kmsManager.providers[kmsTypeVaultTokens] _, ok := kmsManager.providers[kmsTypeVaultTokens]
assert.True(t, ok) assert.True(t, ok)
} }

View File

@ -47,6 +47,7 @@ var testData = []testTuple{
} }
func TestComposeDecomposeID(t *testing.T) { func TestComposeDecomposeID(t *testing.T) {
t.Parallel()
var ( var (
err error err error
viDecompose CSIIdentifier viDecompose CSIIdentifier