mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
cleanup: address golangci 'usetesting' linter issues
When a context.Context is needed in a unit test, t.Context() should be used instead of creating a new one with context.TODO() or context.Background(). Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
committed by
mergify[bot]
parent
be5462cf62
commit
457ffe884a
@ -41,7 +41,7 @@ func TestExecCommandWithTimeout(t *testing.T) {
|
||||
{
|
||||
name: "echo hello",
|
||||
args: args{
|
||||
ctx: context.TODO(),
|
||||
ctx: t.Context(),
|
||||
program: "echo",
|
||||
timeout: time.Second,
|
||||
args: []string{"hello"},
|
||||
@ -53,7 +53,7 @@ func TestExecCommandWithTimeout(t *testing.T) {
|
||||
{
|
||||
name: "sleep with timeout",
|
||||
args: args{
|
||||
ctx: context.TODO(),
|
||||
ctx: t.Context(),
|
||||
program: "sleep",
|
||||
timeout: time.Second,
|
||||
args: []string{"3"},
|
||||
|
@ -295,7 +295,7 @@ func TestGetMappedID(t *testing.T) {
|
||||
|
||||
func TestFetchMappedClusterIDAndMons(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.TODO()
|
||||
ctx := t.Context()
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
clusterID string
|
||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
||||
package util
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"testing"
|
||||
|
||||
@ -56,7 +55,7 @@ func TestKMSWorkflow(t *testing.T) {
|
||||
require.Equal(t, kms.DefaultKMSType, ve.GetID())
|
||||
|
||||
volumeID := "volume-id"
|
||||
ctx := context.TODO()
|
||||
ctx := t.Context()
|
||||
|
||||
err = ve.StoreNewCryptoPassphrase(ctx, volumeID, defaultEncryptionPassphraseSize)
|
||||
require.NoError(t, err)
|
||||
|
@ -14,7 +14,6 @@ limitations under the License.
|
||||
package util
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
@ -35,7 +34,7 @@ func TestGetPassphraseFromKMS(t *testing.T) {
|
||||
|
||||
volEnc, err := NewVolumeEncryption(provider.UniqueID, kms)
|
||||
if errors.Is(err, ErrDEKStoreNeeded) {
|
||||
_, err = volEnc.KMS.GetSecret(context.TODO(), "")
|
||||
_, err = volEnc.KMS.GetSecret(t.Context(), "")
|
||||
if errors.Is(err, kmsapi.ErrGetSecretUnsupported) {
|
||||
continue // currently unsupported by fscrypt integration
|
||||
}
|
||||
@ -46,7 +45,7 @@ func TestGetPassphraseFromKMS(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
|
||||
secret, err := kms.GetSecret(context.TODO(), "")
|
||||
secret, err := kms.GetSecret(t.Context(), "")
|
||||
require.NoError(t, err, provider.UniqueID)
|
||||
require.NotEmpty(t, secret, provider.UniqueID)
|
||||
}
|
||||
|
Reference in New Issue
Block a user