mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-09 16:00:22 +00:00
util: address golangci-lint issues
address golangci-lint issues in utils Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
parent
8c4a38eec6
commit
4b7cafe821
@ -48,7 +48,7 @@ func ExecuteCommandWithNSEnter(ctx context.Context, netPath, program string, arg
|
||||
return "", "", fmt.Errorf("failed to get stat for %s %w", netPath, err)
|
||||
}
|
||||
// nsenter --net=%s -- <program> <args>
|
||||
args = append([]string{fmt.Sprintf("--net=%s", netPath), "--", program}, args...)
|
||||
args = append([]string{"--net=" + netPath, "--", program}, args...)
|
||||
sanitizedArgs := StripSecretInArgs(args)
|
||||
cmd := exec.Command(nsenter, args...) // #nosec:G204, commands executing not vulnerable.
|
||||
cmd.Stdout = &stdoutBuf
|
||||
|
@ -159,7 +159,7 @@ func TestGetClusterMappingInfo(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
clusterMappingConfigFile = fmt.Sprintf("%s/mapping.json", mappingBasePath)
|
||||
clusterMappingConfigFile = mappingBasePath + "/mapping.json"
|
||||
err = os.WriteFile(clusterMappingConfigFile, mappingFileContent, 0o600)
|
||||
if err != nil {
|
||||
t.Errorf("failed to write mapping content error = %v", err)
|
||||
|
@ -19,7 +19,7 @@ package util
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_getCrushLocationMap(t *testing.T) {
|
||||
@ -105,7 +105,7 @@ func Test_getCrushLocationMap(t *testing.T) {
|
||||
currentTT := tt
|
||||
t.Run(currentTT.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert.Equal(t,
|
||||
require.Equal(t,
|
||||
currentTT.want,
|
||||
getCrushLocationMap(currentTT.args.crushLocationLabels, currentTT.args.nodeLabels))
|
||||
})
|
||||
|
@ -23,7 +23,6 @@ import (
|
||||
|
||||
"github.com/ceph/ceph-csi/internal/kms"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@ -35,8 +34,8 @@ func TestGenerateNewEncryptionPassphrase(t *testing.T) {
|
||||
// b64Passphrase is URL-encoded, decode to verify the length of the
|
||||
// passphrase
|
||||
passphrase, err := base64.URLEncoding.DecodeString(b64Passphrase)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, defaultEncryptionPassphraseSize, len(passphrase))
|
||||
require.NoError(t, err)
|
||||
require.Len(t, passphrase, defaultEncryptionPassphraseSize)
|
||||
}
|
||||
|
||||
func TestKMSWorkflow(t *testing.T) {
|
||||
@ -47,52 +46,52 @@ func TestKMSWorkflow(t *testing.T) {
|
||||
}
|
||||
|
||||
kmsProvider, err := kms.GetDefaultKMS(secrets)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, kmsProvider)
|
||||
|
||||
ve, err := NewVolumeEncryption("", kmsProvider)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, ve)
|
||||
assert.Equal(t, kms.DefaultKMSType, ve.GetID())
|
||||
require.Equal(t, kms.DefaultKMSType, ve.GetID())
|
||||
|
||||
volumeID := "volume-id"
|
||||
ctx := context.TODO()
|
||||
|
||||
err = ve.StoreNewCryptoPassphrase(ctx, volumeID, defaultEncryptionPassphraseSize)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
passphrase, err := ve.GetCryptoPassphrase(ctx, volumeID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, secrets["encryptionPassphrase"], passphrase)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, secrets["encryptionPassphrase"], passphrase)
|
||||
}
|
||||
|
||||
func TestEncryptionType(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert.EqualValues(t, EncryptionTypeInvalid, ParseEncryptionType("wat?"))
|
||||
assert.EqualValues(t, EncryptionTypeInvalid, ParseEncryptionType("both"))
|
||||
assert.EqualValues(t, EncryptionTypeInvalid, ParseEncryptionType("file,block"))
|
||||
assert.EqualValues(t, EncryptionTypeInvalid, ParseEncryptionType("block,file"))
|
||||
assert.EqualValues(t, EncryptionTypeBlock, ParseEncryptionType("block"))
|
||||
assert.EqualValues(t, EncryptionTypeFile, ParseEncryptionType("file"))
|
||||
assert.EqualValues(t, EncryptionTypeNone, ParseEncryptionType(""))
|
||||
require.EqualValues(t, EncryptionTypeInvalid, ParseEncryptionType("wat?"))
|
||||
require.EqualValues(t, EncryptionTypeInvalid, ParseEncryptionType("both"))
|
||||
require.EqualValues(t, EncryptionTypeInvalid, ParseEncryptionType("file,block"))
|
||||
require.EqualValues(t, EncryptionTypeInvalid, ParseEncryptionType("block,file"))
|
||||
require.EqualValues(t, EncryptionTypeBlock, ParseEncryptionType("block"))
|
||||
require.EqualValues(t, EncryptionTypeFile, ParseEncryptionType("file"))
|
||||
require.EqualValues(t, EncryptionTypeNone, ParseEncryptionType(""))
|
||||
|
||||
for _, s := range []string{"file", "block", ""} {
|
||||
assert.EqualValues(t, s, ParseEncryptionType(s).String())
|
||||
require.EqualValues(t, s, ParseEncryptionType(s).String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestFetchEncryptionType(t *testing.T) {
|
||||
t.Parallel()
|
||||
volOpts := map[string]string{}
|
||||
assert.EqualValues(t, EncryptionTypeBlock, FetchEncryptionType(volOpts, EncryptionTypeBlock))
|
||||
assert.EqualValues(t, EncryptionTypeFile, FetchEncryptionType(volOpts, EncryptionTypeFile))
|
||||
assert.EqualValues(t, EncryptionTypeNone, FetchEncryptionType(volOpts, EncryptionTypeNone))
|
||||
require.EqualValues(t, EncryptionTypeBlock, FetchEncryptionType(volOpts, EncryptionTypeBlock))
|
||||
require.EqualValues(t, EncryptionTypeFile, FetchEncryptionType(volOpts, EncryptionTypeFile))
|
||||
require.EqualValues(t, EncryptionTypeNone, FetchEncryptionType(volOpts, EncryptionTypeNone))
|
||||
volOpts["encryptionType"] = ""
|
||||
assert.EqualValues(t, EncryptionTypeInvalid, FetchEncryptionType(volOpts, EncryptionTypeNone))
|
||||
require.EqualValues(t, EncryptionTypeInvalid, FetchEncryptionType(volOpts, EncryptionTypeNone))
|
||||
volOpts["encryptionType"] = "block"
|
||||
assert.EqualValues(t, EncryptionTypeBlock, FetchEncryptionType(volOpts, EncryptionTypeNone))
|
||||
require.EqualValues(t, EncryptionTypeBlock, FetchEncryptionType(volOpts, EncryptionTypeNone))
|
||||
volOpts["encryptionType"] = "file"
|
||||
assert.EqualValues(t, EncryptionTypeFile, FetchEncryptionType(volOpts, EncryptionTypeNone))
|
||||
require.EqualValues(t, EncryptionTypeFile, FetchEncryptionType(volOpts, EncryptionTypeNone))
|
||||
volOpts["encryptionType"] = "INVALID"
|
||||
assert.EqualValues(t, EncryptionTypeInvalid, FetchEncryptionType(volOpts, EncryptionTypeNone))
|
||||
require.EqualValues(t, EncryptionTypeInvalid, FetchEncryptionType(volOpts, EncryptionTypeNone))
|
||||
}
|
||||
|
@ -463,5 +463,5 @@ func Unlock(
|
||||
return initializeAndUnlock(ctx, fscryptContext, encryptedPath, protectorName, keyFn)
|
||||
}
|
||||
|
||||
return fmt.Errorf("unsupported")
|
||||
return errors.New("unsupported")
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
|
||||
kmsapi "github.com/ceph/ceph-csi/internal/kms"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGetPassphraseFromKMS(t *testing.T) {
|
||||
@ -31,7 +31,7 @@ func TestGetPassphraseFromKMS(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
kms := kmsapi.GetKMSTestDummy(provider.UniqueID)
|
||||
assert.NotNil(t, kms)
|
||||
require.NotNil(t, kms)
|
||||
|
||||
volEnc, err := NewVolumeEncryption(provider.UniqueID, kms)
|
||||
if errors.Is(err, ErrDEKStoreNeeded) {
|
||||
@ -40,14 +40,14 @@ func TestGetPassphraseFromKMS(t *testing.T) {
|
||||
continue // currently unsupported by fscrypt integration
|
||||
}
|
||||
}
|
||||
assert.NotNil(t, volEnc)
|
||||
require.NotNil(t, volEnc)
|
||||
|
||||
if kms.RequiresDEKStore() == kmsapi.DEKStoreIntegrated {
|
||||
continue
|
||||
}
|
||||
|
||||
secret, err := kms.GetSecret(context.TODO(), "")
|
||||
assert.NoError(t, err, provider.UniqueID)
|
||||
assert.NotEmpty(t, secret, provider.UniqueID)
|
||||
require.NoError(t, err, provider.UniqueID)
|
||||
require.NotEmpty(t, secret, provider.UniqueID)
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ func getCgroupPidsFile() (string, error) {
|
||||
}
|
||||
}
|
||||
if slice == "" {
|
||||
return "", fmt.Errorf("could not find a cgroup for 'pids'")
|
||||
return "", errors.New("could not find a cgroup for 'pids'")
|
||||
}
|
||||
|
||||
return pidsMax, nil
|
||||
@ -112,7 +112,7 @@ func GetPIDLimit() (int, error) {
|
||||
func SetPIDLimit(limit int) error {
|
||||
limitStr := "max"
|
||||
if limit != -1 {
|
||||
limitStr = fmt.Sprintf("%d", limit)
|
||||
limitStr = strconv.Itoa(limit)
|
||||
}
|
||||
|
||||
pidsMax, err := getCgroupPidsFile()
|
||||
|
@ -19,7 +19,7 @@ package util
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestReadAffinity_ConstructReadAffinityMapOption(t *testing.T) {
|
||||
@ -62,7 +62,7 @@ func TestReadAffinity_ConstructReadAffinityMapOption(t *testing.T) {
|
||||
currentTT := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert.Contains(t, currentTT.wantAny, ConstructReadAffinityMapOption(currentTT.crushLocationmap))
|
||||
require.Contains(t, currentTT.wantAny, ConstructReadAffinityMapOption(currentTT.crushLocationmap))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,6 @@ func TryRADOSAborted(opErr error) error {
|
||||
return opErr
|
||||
}
|
||||
|
||||
//nolint:errorlint // Can't use errors.As() because rados.radosError is private.
|
||||
errnoErr, ok := radosOpErr.OpError.(interface{ ErrorCode() int })
|
||||
if !ok {
|
||||
return opErr
|
||||
|
@ -22,7 +22,7 @@ import (
|
||||
"github.com/ceph/ceph-csi/internal/util/reftracker/radoswrapper"
|
||||
"github.com/ceph/ceph-csi/internal/util/reftracker/reftype"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const rtName = "hello-rt"
|
||||
@ -36,8 +36,8 @@ func TestRTAdd(t *testing.T) {
|
||||
|
||||
ioctx := radoswrapper.NewFakeIOContext(radoswrapper.NewFakeRados())
|
||||
created, err := Add(ioctx, "", nil)
|
||||
assert.Error(ts, err)
|
||||
assert.False(ts, created)
|
||||
require.Error(ts, err)
|
||||
require.False(ts, created)
|
||||
})
|
||||
|
||||
// Verify input validation for nil and empty refs.
|
||||
@ -51,8 +51,8 @@ func TestRTAdd(t *testing.T) {
|
||||
}
|
||||
for _, ref := range refs {
|
||||
created, err := Add(ioctx, rtName, ref)
|
||||
assert.Error(ts, err)
|
||||
assert.False(ts, created)
|
||||
require.Error(ts, err)
|
||||
require.False(ts, created)
|
||||
}
|
||||
})
|
||||
|
||||
@ -66,8 +66,8 @@ func TestRTAdd(t *testing.T) {
|
||||
"ref2": {},
|
||||
"ref3": {},
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, created)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, created)
|
||||
})
|
||||
|
||||
// Add refs where each Add() has some of the refs overlapping
|
||||
@ -80,8 +80,8 @@ func TestRTAdd(t *testing.T) {
|
||||
"ref1": {},
|
||||
"ref2": {},
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, created)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, created)
|
||||
|
||||
refsTable := []map[string]struct{}{
|
||||
{"ref2": {}, "ref3": {}},
|
||||
@ -90,8 +90,8 @@ func TestRTAdd(t *testing.T) {
|
||||
}
|
||||
for _, refs := range refsTable {
|
||||
created, err = Add(ioctx, rtName, refs)
|
||||
assert.NoError(ts, err)
|
||||
assert.False(ts, created)
|
||||
require.NoError(ts, err)
|
||||
require.False(ts, created)
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -110,8 +110,8 @@ func TestRTRemove(t *testing.T) {
|
||||
}
|
||||
for _, ref := range refs {
|
||||
created, err := Remove(ioctx, rtName, ref)
|
||||
assert.Error(ts, err)
|
||||
assert.False(ts, created)
|
||||
require.Error(ts, err)
|
||||
require.False(ts, created)
|
||||
}
|
||||
})
|
||||
|
||||
@ -124,8 +124,8 @@ func TestRTRemove(t *testing.T) {
|
||||
deleted, err := Remove(ioctx, "xxx", map[string]reftype.RefType{
|
||||
"ref1": reftype.Normal,
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, deleted)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, deleted)
|
||||
})
|
||||
|
||||
// Removing only non-existent refs should not result in reftracker object
|
||||
@ -140,16 +140,16 @@ func TestRTRemove(t *testing.T) {
|
||||
"ref2": {},
|
||||
"ref3": {},
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, created)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, created)
|
||||
|
||||
deleted, err := Remove(ioctx, rtName, map[string]reftype.RefType{
|
||||
"refX": reftype.Normal,
|
||||
"refY": reftype.Normal,
|
||||
"refZ": reftype.Normal,
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.False(ts, deleted)
|
||||
require.NoError(ts, err)
|
||||
require.False(ts, deleted)
|
||||
})
|
||||
|
||||
// Removing all refs plus some surplus should result in reftracker object
|
||||
@ -162,8 +162,8 @@ func TestRTRemove(t *testing.T) {
|
||||
created, err := Add(ioctx, rtName, map[string]struct{}{
|
||||
"ref": {},
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, created)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, created)
|
||||
|
||||
deleted, err := Remove(ioctx, rtName, map[string]reftype.RefType{
|
||||
"refX": reftype.Normal,
|
||||
@ -171,8 +171,8 @@ func TestRTRemove(t *testing.T) {
|
||||
"ref": reftype.Normal,
|
||||
"refZ": reftype.Normal,
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, deleted)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, deleted)
|
||||
})
|
||||
|
||||
// Bulk removal of all refs should result in reftracker object deletion.
|
||||
@ -189,12 +189,12 @@ func TestRTRemove(t *testing.T) {
|
||||
}
|
||||
|
||||
created, err := Add(ioctx, rtName, refsToAdd)
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, created)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, created)
|
||||
|
||||
deleted, err := Remove(ioctx, rtName, refsToRemove)
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, deleted)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, deleted)
|
||||
})
|
||||
|
||||
// Removal of all refs one-by-one should result in reftracker object deletion
|
||||
@ -209,23 +209,23 @@ func TestRTRemove(t *testing.T) {
|
||||
"ref2": {},
|
||||
"ref3": {},
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, created)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, created)
|
||||
|
||||
for _, k := range []string{"ref3", "ref2"} {
|
||||
deleted, errRemove := Remove(ioctx, rtName, map[string]reftype.RefType{
|
||||
k: reftype.Normal,
|
||||
})
|
||||
assert.NoError(ts, errRemove)
|
||||
assert.False(ts, deleted)
|
||||
require.NoError(ts, errRemove)
|
||||
require.False(ts, deleted)
|
||||
}
|
||||
|
||||
// Remove the last reference. It should remove the whole reftracker object too.
|
||||
deleted, err := Remove(ioctx, rtName, map[string]reftype.RefType{
|
||||
"ref1": reftype.Normal,
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, deleted)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, deleted)
|
||||
})
|
||||
|
||||
// Cycle through reftracker object twice.
|
||||
@ -246,12 +246,12 @@ func TestRTRemove(t *testing.T) {
|
||||
|
||||
for i := 0; i < 2; i++ {
|
||||
created, err := Add(ioctx, rtName, refsToAdd)
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, created)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, created)
|
||||
|
||||
deleted, err := Remove(ioctx, rtName, refsToRemove)
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, deleted)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, deleted)
|
||||
}
|
||||
})
|
||||
|
||||
@ -265,8 +265,8 @@ func TestRTRemove(t *testing.T) {
|
||||
"ref1": {},
|
||||
"ref2": {},
|
||||
})
|
||||
assert.True(ts, created)
|
||||
assert.NoError(ts, err)
|
||||
require.True(ts, created)
|
||||
require.NoError(ts, err)
|
||||
refsTable := []map[string]struct{}{
|
||||
{"ref2": {}, "ref3": {}},
|
||||
{"ref3": {}, "ref4": {}},
|
||||
@ -274,8 +274,8 @@ func TestRTRemove(t *testing.T) {
|
||||
}
|
||||
for _, refs := range refsTable {
|
||||
created, err = Add(ioctx, rtName, refs)
|
||||
assert.False(ts, created)
|
||||
assert.NoError(ts, err)
|
||||
require.False(ts, created)
|
||||
require.NoError(ts, err)
|
||||
}
|
||||
|
||||
deleted, err := Remove(ioctx, rtName, map[string]reftype.RefType{
|
||||
@ -285,8 +285,8 @@ func TestRTRemove(t *testing.T) {
|
||||
"ref4": reftype.Normal,
|
||||
"ref5": reftype.Normal,
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, deleted)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, deleted)
|
||||
})
|
||||
}
|
||||
|
||||
@ -307,12 +307,12 @@ func TestRTMask(t *testing.T) {
|
||||
}
|
||||
|
||||
created, err := Add(ioctx, rtName, refsToAdd)
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, created)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, created)
|
||||
|
||||
deleted, err := Remove(ioctx, rtName, refsToRemove)
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, deleted)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, deleted)
|
||||
})
|
||||
|
||||
// Masking all refs one-by-one should result in reftracker object deletion in
|
||||
@ -327,15 +327,15 @@ func TestRTMask(t *testing.T) {
|
||||
"ref2": {},
|
||||
"ref3": {},
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, created)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, created)
|
||||
|
||||
for _, k := range []string{"ref3", "ref2"} {
|
||||
deleted, errRemove := Remove(ioctx, rtName, map[string]reftype.RefType{
|
||||
k: reftype.Mask,
|
||||
})
|
||||
assert.NoError(ts, errRemove)
|
||||
assert.False(ts, deleted)
|
||||
require.NoError(ts, errRemove)
|
||||
require.False(ts, deleted)
|
||||
}
|
||||
|
||||
// Remove the last reference. It should delete the whole reftracker object
|
||||
@ -343,8 +343,8 @@ func TestRTMask(t *testing.T) {
|
||||
deleted, err := Remove(ioctx, rtName, map[string]reftype.RefType{
|
||||
"ref1": reftype.Mask,
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, deleted)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, deleted)
|
||||
})
|
||||
|
||||
// Bulk removing two (out of 3) refs and then masking the ref that's left
|
||||
@ -359,21 +359,21 @@ func TestRTMask(t *testing.T) {
|
||||
"ref2": {},
|
||||
"ref3": {},
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, created)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, created)
|
||||
|
||||
deleted, err := Remove(ioctx, rtName, map[string]reftype.RefType{
|
||||
"ref1": reftype.Normal,
|
||||
"ref2": reftype.Normal,
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.False(ts, deleted)
|
||||
require.NoError(ts, err)
|
||||
require.False(ts, deleted)
|
||||
|
||||
deleted, err = Remove(ioctx, rtName, map[string]reftype.RefType{
|
||||
"ref3": reftype.Mask,
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, deleted)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, deleted)
|
||||
})
|
||||
|
||||
// Bulk masking two (out of 3) refs and then removing the ref that's left
|
||||
@ -388,21 +388,21 @@ func TestRTMask(t *testing.T) {
|
||||
"ref2": {},
|
||||
"ref3": {},
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, created)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, created)
|
||||
|
||||
deleted, err := Remove(ioctx, rtName, map[string]reftype.RefType{
|
||||
"ref1": reftype.Mask,
|
||||
"ref2": reftype.Mask,
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.False(ts, deleted)
|
||||
require.NoError(ts, err)
|
||||
require.False(ts, deleted)
|
||||
|
||||
deleted, err = Remove(ioctx, rtName, map[string]reftype.RefType{
|
||||
"ref3": reftype.Normal,
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, deleted)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, deleted)
|
||||
})
|
||||
|
||||
// Verify that masking refs hides them from future Add()s.
|
||||
@ -416,28 +416,28 @@ func TestRTMask(t *testing.T) {
|
||||
"ref2": {},
|
||||
"ref3": {},
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, created)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, created)
|
||||
|
||||
deleted, err := Remove(ioctx, rtName, map[string]reftype.RefType{
|
||||
"ref1": reftype.Mask,
|
||||
"ref2": reftype.Mask,
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.False(ts, deleted)
|
||||
require.NoError(ts, err)
|
||||
require.False(ts, deleted)
|
||||
|
||||
created, err = Add(ioctx, rtName, map[string]struct{}{
|
||||
"ref1": {},
|
||||
"ref2": {},
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.False(ts, created)
|
||||
require.NoError(ts, err)
|
||||
require.False(ts, created)
|
||||
|
||||
deleted, err = Remove(ioctx, rtName, map[string]reftype.RefType{
|
||||
"ref3": reftype.Normal,
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, deleted)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, deleted)
|
||||
})
|
||||
|
||||
// Verify that masked refs may be removed with reftype.Normal and re-added.
|
||||
@ -451,41 +451,41 @@ func TestRTMask(t *testing.T) {
|
||||
"ref2": {},
|
||||
"ref3": {},
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, created)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, created)
|
||||
|
||||
deleted, err := Remove(ioctx, rtName, map[string]reftype.RefType{
|
||||
"ref1": reftype.Mask,
|
||||
"ref2": reftype.Mask,
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.False(ts, deleted)
|
||||
require.NoError(ts, err)
|
||||
require.False(ts, deleted)
|
||||
|
||||
deleted, err = Remove(ioctx, rtName, map[string]reftype.RefType{
|
||||
"ref1": reftype.Normal,
|
||||
"ref2": reftype.Normal,
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.False(ts, deleted)
|
||||
require.NoError(ts, err)
|
||||
require.False(ts, deleted)
|
||||
|
||||
created, err = Add(ioctx, rtName, map[string]struct{}{
|
||||
"ref1": {},
|
||||
"ref2": {},
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.False(ts, created)
|
||||
require.NoError(ts, err)
|
||||
require.False(ts, created)
|
||||
|
||||
deleted, err = Remove(ioctx, rtName, map[string]reftype.RefType{
|
||||
"ref3": reftype.Normal,
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.False(ts, deleted)
|
||||
require.NoError(ts, err)
|
||||
require.False(ts, deleted)
|
||||
|
||||
deleted, err = Remove(ioctx, rtName, map[string]reftype.RefType{
|
||||
"ref1": reftype.Normal,
|
||||
"ref2": reftype.Normal,
|
||||
})
|
||||
assert.NoError(ts, err)
|
||||
assert.True(ts, deleted)
|
||||
require.NoError(ts, err)
|
||||
require.True(ts, deleted)
|
||||
})
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ package reftype
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestRefTypeBytes(t *testing.T) {
|
||||
@ -41,7 +41,7 @@ func TestRefTypeBytes(t *testing.T) {
|
||||
|
||||
for i := range expectedBytes {
|
||||
bs := ToBytes(refTypes[i])
|
||||
assert.Equal(ts, expectedBytes[i], bs)
|
||||
require.Equal(ts, expectedBytes[i], bs)
|
||||
}
|
||||
})
|
||||
|
||||
@ -50,14 +50,14 @@ func TestRefTypeBytes(t *testing.T) {
|
||||
|
||||
for i := range refTypes {
|
||||
refType, err := FromBytes(expectedBytes[i])
|
||||
assert.NoError(ts, err)
|
||||
assert.Equal(ts, refTypes[i], refType)
|
||||
require.NoError(ts, err)
|
||||
require.Equal(ts, refTypes[i], refType)
|
||||
}
|
||||
|
||||
_, err := FromBytes(refTypeInvalidBytes)
|
||||
assert.Error(ts, err)
|
||||
require.Error(ts, err)
|
||||
|
||||
_, err = FromBytes(refTypeWrongSizeBytes)
|
||||
assert.Error(ts, err)
|
||||
require.Error(ts, err)
|
||||
})
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ package v1
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestV1RefCountBytes(t *testing.T) {
|
||||
@ -35,17 +35,17 @@ func TestV1RefCountBytes(t *testing.T) {
|
||||
ts.Parallel()
|
||||
|
||||
bs := refCountValue.toBytes()
|
||||
assert.Equal(ts, refCountBytes, bs)
|
||||
require.Equal(ts, refCountBytes, bs)
|
||||
})
|
||||
|
||||
t.Run("FromBytes", func(ts *testing.T) {
|
||||
ts.Parallel()
|
||||
|
||||
rc, err := refCountFromBytes(refCountBytes)
|
||||
assert.NoError(ts, err)
|
||||
assert.Equal(ts, refCountValue, rc)
|
||||
require.NoError(ts, err)
|
||||
require.Equal(ts, refCountValue, rc)
|
||||
|
||||
_, err = refCountFromBytes(wrongSizeRefCountBytes)
|
||||
assert.Error(ts, err)
|
||||
require.Error(ts, err)
|
||||
})
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ func Remove(
|
||||
|
||||
if rcToSubtract > readRes.total {
|
||||
// BUG: this should never happen!
|
||||
return false, fmt.Errorf("refcount underflow, reftracker object corrupted")
|
||||
return false, goerrors.New("refcount underflow, reftracker object corrupted")
|
||||
}
|
||||
|
||||
newRC := readRes.total - rcToSubtract
|
||||
|
@ -17,14 +17,13 @@ limitations under the License.
|
||||
package v1
|
||||
|
||||
import (
|
||||
goerrors "errors"
|
||||
"testing"
|
||||
|
||||
"github.com/ceph/ceph-csi/internal/util/reftracker/errors"
|
||||
"github.com/ceph/ceph-csi/internal/util/reftracker/radoswrapper"
|
||||
"github.com/ceph/ceph-csi/internal/util/reftracker/reftype"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestV1Read(t *testing.T) {
|
||||
@ -73,17 +72,17 @@ func TestV1Read(t *testing.T) {
|
||||
)
|
||||
|
||||
err := Add(validObj, rtName, gen, refsToAdd)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
for i := range invalidObjs {
|
||||
err = Add(invalidObjs[i], rtName, gen, refsToAdd)
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
// Check for correct error type for wrong gen num.
|
||||
err = Add(invalidObjs[1], rtName, gen, refsToAdd)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, goerrors.Is(err, errors.ErrObjectOutOfDate))
|
||||
require.Error(t, err)
|
||||
require.ErrorIs(t, err, errors.ErrObjectOutOfDate)
|
||||
}
|
||||
|
||||
func TestV1Init(t *testing.T) {
|
||||
@ -106,10 +105,10 @@ func TestV1Init(t *testing.T) {
|
||||
)
|
||||
|
||||
err := Init(emptyRados, rtName, refsToInit)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = Init(alreadyExists, rtName, refsToInit)
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestV1Add(t *testing.T) {
|
||||
@ -224,19 +223,19 @@ func TestV1Add(t *testing.T) {
|
||||
ioctx.Rados.Objs[rtName] = shouldSucceed[i].before
|
||||
|
||||
err := Add(ioctx, rtName, 0, shouldSucceed[i].refsToAdd)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, shouldSucceed[i].after, ioctx.Rados.Objs[rtName])
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, shouldSucceed[i].after, ioctx.Rados.Objs[rtName])
|
||||
}
|
||||
|
||||
for i := range shouldFail {
|
||||
err := Add(shouldFail[i], rtName, 0, map[string]struct{}{"ref1": {}})
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
// Check for correct error type for wrong gen num.
|
||||
err := Add(shouldFail[1], rtName, 0, map[string]struct{}{"ref1": {}})
|
||||
assert.Error(t, err)
|
||||
assert.True(t, goerrors.Is(err, errors.ErrObjectOutOfDate))
|
||||
require.Error(t, err)
|
||||
require.ErrorIs(t, err, errors.ErrObjectOutOfDate)
|
||||
}
|
||||
|
||||
func TestV1Remove(t *testing.T) {
|
||||
@ -412,12 +411,12 @@ func TestV1Remove(t *testing.T) {
|
||||
ioctx.Rados.Objs[rtName] = shouldSucceed[i].before
|
||||
|
||||
deleted, err := Remove(ioctx, rtName, 0, shouldSucceed[i].refsToRemove)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, shouldSucceed[i].deleted, deleted)
|
||||
assert.Equal(t, shouldSucceed[i].after, ioctx.Rados.Objs[rtName])
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, shouldSucceed[i].deleted, deleted)
|
||||
require.Equal(t, shouldSucceed[i].after, ioctx.Rados.Objs[rtName])
|
||||
}
|
||||
|
||||
_, err := Remove(badGen, rtName, 0, map[string]reftype.RefType{"ref": reftype.Normal})
|
||||
assert.Error(t, err)
|
||||
assert.True(t, goerrors.Is(err, errors.ErrObjectOutOfDate))
|
||||
require.Error(t, err)
|
||||
require.ErrorIs(t, err, errors.ErrObjectOutOfDate)
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
|
||||
"github.com/ceph/ceph-csi/internal/util/reftracker/radoswrapper"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -38,18 +38,18 @@ func TestVersionBytes(t *testing.T) {
|
||||
ts.Parallel()
|
||||
|
||||
bs := ToBytes(v1Value)
|
||||
assert.Equal(ts, v1Bytes, bs)
|
||||
require.Equal(ts, v1Bytes, bs)
|
||||
})
|
||||
|
||||
t.Run("FromBytes", func(ts *testing.T) {
|
||||
ts.Parallel()
|
||||
|
||||
ver, err := FromBytes(v1Bytes)
|
||||
assert.NoError(ts, err)
|
||||
assert.Equal(ts, v1Value, ver)
|
||||
require.NoError(ts, err)
|
||||
require.Equal(ts, v1Value, ver)
|
||||
|
||||
_, err = FromBytes(wrongSizeVersionBytes)
|
||||
assert.Error(ts, err)
|
||||
require.Error(ts, err)
|
||||
})
|
||||
}
|
||||
|
||||
@ -101,11 +101,11 @@ func TestVersionRead(t *testing.T) {
|
||||
)
|
||||
|
||||
ver, err := Read(validObj, rtName)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, v1Value, ver)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, v1Value, ver)
|
||||
|
||||
for i := range invalidObjs {
|
||||
_, err = Read(invalidObjs[i], rtName)
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
}
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ func parseKernelRelease(release string) (int, int, int, int, error) {
|
||||
extraversion := 0
|
||||
if n > minVersions {
|
||||
n, err = fmt.Sscanf(extra, ".%d%s", &sublevel, &extra)
|
||||
if err != nil && n == 0 && len(extra) > 0 && extra[0] != '-' && extra[0] == '.' {
|
||||
if err != nil && n == 0 && extra != "" && extra[0] != '-' && extra[0] == '.' {
|
||||
return 0, 0, 0, 0, fmt.Errorf("failed to parse subversion from %s: %w", release, err)
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ func ValidateNodeUnpublishVolumeRequest(req *csi.NodeUnpublishVolumeRequest) err
|
||||
// volume is from source as empty ReadOnlyMany is not supported.
|
||||
func CheckReadOnlyManyIsSupported(req *csi.CreateVolumeRequest) error {
|
||||
for _, capability := range req.GetVolumeCapabilities() {
|
||||
if m := capability.GetAccessMode().Mode; m == csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY ||
|
||||
if m := capability.GetAccessMode().GetMode(); m == csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY ||
|
||||
m == csi.VolumeCapability_AccessMode_SINGLE_NODE_READER_ONLY {
|
||||
if req.GetVolumeContentSource() == nil {
|
||||
return status.Error(codes.InvalidArgument, "readOnly accessMode is supported only with content source")
|
||||
|
Loading…
Reference in New Issue
Block a user