Skip to content

Commit

Permalink
Enable linter revive and resolve found errors: part 2.
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Jiang <blackpiglet@gmail.com>
  • Loading branch information
Xun Jiang committed Apr 25, 2023
1 parent a0b0b7c commit a22a345
Show file tree
Hide file tree
Showing 35 changed files with 108 additions and 116 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/6177-blackpiglet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enable linter revive and resolve found errors: part 2
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (r *RestartableBackupItemAction) getBackupItemAction() (biav1.BackupItemAct

backupItemAction, ok := plugin.(biav1.BackupItemAction)
if !ok {
return nil, errors.Errorf("%T is not a BackupItemAction!", plugin)
return nil, errors.Errorf("plugin %T is not a BackupItemAction", plugin)
}

return backupItemAction, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestRestartableGetBackupItemAction(t *testing.T) {
{
name: "wrong type",
plugin: 3,
expectedError: "int is not a BackupItemAction!",
expectedError: "plugin int is not a BackupItemAction",
},
{
name: "happy path",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (r *RestartableBackupItemAction) getBackupItemAction() (biav2.BackupItemAct

backupItemAction, ok := plugin.(biav2.BackupItemAction)
if !ok {
return nil, errors.Errorf("%T (returned for %v) is not a BackupItemActionV2!", plugin, r.Key)
return nil, errors.Errorf("plugin %T (returned for %v) is not a BackupItemActionV2", plugin, r.Key)
}

return backupItemAction, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestRestartableGetBackupItemAction(t *testing.T) {
{
name: "wrong type",
plugin: 3,
expectedError: "int (returned for {BackupItemActionV2 pod}) is not a BackupItemActionV2!",
expectedError: "plugin int (returned for {BackupItemActionV2 pod}) is not a BackupItemActionV2",
},
{
name: "happy path",
Expand Down
4 changes: 2 additions & 2 deletions pkg/plugin/clientmgmt/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (m *manager) GetObjectStore(name string) (velero.ObjectStore, error) {
return nil, err
}

r := NewRestartableObjectStore(name, restartableProcess)
r := newRestartableObjectStore(name, restartableProcess)

return r, nil
}
Expand Down Expand Up @@ -370,7 +370,7 @@ func (m *manager) GetDeleteItemAction(name string) (velero.DeleteItemAction, err
return nil, err
}

r := NewRestartableDeleteItemAction(name, restartableProcess)
r := newRestartableDeleteItemAction(name, restartableProcess)
return r, nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/plugin/clientmgmt/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import (
"github.com/vmware-tanzu/velero/pkg/plugin/framework/common"
)

type ProcessFactory interface {
type Factory interface {
newProcess(command string, logger logrus.FieldLogger, logLevel logrus.Level) (Process, error)
}

type processFactory struct {
}

func newProcessFactory() ProcessFactory {
func newProcessFactory() Factory {
return &processFactory{}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/clientmgmt/process/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type registry struct {
logger logrus.FieldLogger
logLevel logrus.Level

processFactory ProcessFactory
processFactory Factory
fs filesystem.Interface
pluginsByID map[KindAndName]framework.PluginIdentifier
pluginsByKind map[common.PluginKind][]framework.PluginIdentifier
Expand Down
6 changes: 3 additions & 3 deletions pkg/plugin/clientmgmt/restartable_delete_item_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ type restartableDeleteItemAction struct {
sharedPluginProcess process.RestartableProcess
}

// NewRestartableDeleteItemAction returns a new restartableDeleteItemAction.
func NewRestartableDeleteItemAction(name string, sharedPluginProcess process.RestartableProcess) *restartableDeleteItemAction {
// newRestartableDeleteItemAction returns a new restartableDeleteItemAction.
func newRestartableDeleteItemAction(name string, sharedPluginProcess process.RestartableProcess) *restartableDeleteItemAction {
r := &restartableDeleteItemAction{
key: process.KindAndName{Kind: common.PluginKindDeleteItemAction, Name: name},
sharedPluginProcess: sharedPluginProcess,
Expand All @@ -52,7 +52,7 @@ func (r *restartableDeleteItemAction) getDeleteItemAction() (velero.DeleteItemAc

deleteItemAction, ok := plugin.(velero.DeleteItemAction)
if !ok {
return nil, errors.Errorf("%T is not a DeleteItemAction!", plugin)
return nil, errors.Errorf("plugin %T is not a DeleteItemAction", plugin)
}

return deleteItemAction, nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/plugin/clientmgmt/restartable_delete_item_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestRestartableGetDeleteItemAction(t *testing.T) {
{
name: "wrong type",
plugin: 3,
expectedError: "int is not a DeleteItemAction!",
expectedError: "plugin int is not a DeleteItemAction",
},
{
name: "happy path",
Expand All @@ -64,7 +64,7 @@ func TestRestartableGetDeleteItemAction(t *testing.T) {
key := process.KindAndName{Kind: common.PluginKindDeleteItemAction, Name: name}
p.On("GetByKindAndName", key).Return(tc.plugin, tc.getError)

r := NewRestartableDeleteItemAction(name, p)
r := newRestartableDeleteItemAction(name, p)
a, err := r.getDeleteItemAction()
if tc.expectedError != "" {
assert.EqualError(t, err, tc.expectedError)
Expand All @@ -84,7 +84,7 @@ func TestRestartableDeleteItemActionGetDelegate(t *testing.T) {
// Reset error
p.On("ResetIfNeeded").Return(errors.Errorf("reset error")).Once()
name := "pod"
r := NewRestartableDeleteItemAction(name, p)
r := newRestartableDeleteItemAction(name, p)
a, err := r.getDelegate()
assert.Nil(t, a)
assert.EqualError(t, err, "reset error")
Expand Down
8 changes: 4 additions & 4 deletions pkg/plugin/clientmgmt/restartable_object_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ type restartableObjectStore struct {
config map[string]string
}

// NewRestartableObjectStore returns a new restartableObjectStore.
func NewRestartableObjectStore(name string, sharedPluginProcess process.RestartableProcess) *restartableObjectStore {
// newRestartableObjectStore returns a new restartableObjectStore.
func newRestartableObjectStore(name string, sharedPluginProcess process.RestartableProcess) *restartableObjectStore {
key := process.KindAndName{Kind: common.PluginKindObjectStore, Name: name}
r := &restartableObjectStore{
key: key,
Expand All @@ -57,7 +57,7 @@ func NewRestartableObjectStore(name string, sharedPluginProcess process.Restarta
func (r *restartableObjectStore) Reinitialize(dispensed interface{}) error {
objectStore, ok := dispensed.(velero.ObjectStore)
if !ok {
return errors.Errorf("%T is not a ObjectStore!", dispensed)
return errors.Errorf("plugin %T is not a ObjectStore", dispensed)
}

return r.init(objectStore, r.config)
Expand All @@ -73,7 +73,7 @@ func (r *restartableObjectStore) getObjectStore() (velero.ObjectStore, error) {

objectStore, ok := plugin.(velero.ObjectStore)
if !ok {
return nil, errors.Errorf("%T is not a ObjectStore!", plugin)
return nil, errors.Errorf("plugin %T is not a ObjectStore", plugin)
}

return objectStore, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/plugin/clientmgmt/restartable_object_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestRestartableGetObjectStore(t *testing.T) {
{
name: "wrong type",
plugin: 3,
expectedError: "int is not a ObjectStore!",
expectedError: "plugin int is not a ObjectStore",
},
{
name: "happy path",
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestRestartableObjectStoreReinitialize(t *testing.T) {
}

err := r.Reinitialize(3)
assert.EqualError(t, err, "int is not a ObjectStore!")
assert.EqualError(t, err, "plugin int is not a ObjectStore")

objectStore := new(providermocks.ObjectStore)
objectStore.Test(t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (r *RestartableRestoreItemAction) getRestoreItemAction() (riav1.RestoreItem

restoreItemAction, ok := plugin.(riav1.RestoreItemAction)
if !ok {
return nil, errors.Errorf("%T is not a RestoreItemAction!", plugin)
return nil, errors.Errorf("plugin %T is not a RestoreItemAction", plugin)
}

return restoreItemAction, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestRestartableGetRestoreItemAction(t *testing.T) {
{
name: "wrong type",
plugin: 3,
expectedError: "int is not a RestoreItemAction!",
expectedError: "plugin int is not a RestoreItemAction",
},
{
name: "happy path",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (r *RestartableRestoreItemAction) getRestoreItemAction() (riav2.RestoreItem

restoreItemAction, ok := plugin.(riav2.RestoreItemAction)
if !ok {
return nil, errors.Errorf("%T is not a RestoreItemActionV2!", plugin)
return nil, errors.Errorf("plugin %T is not a RestoreItemActionV2", plugin)
}

return restoreItemAction, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestRestartableGetRestoreItemAction(t *testing.T) {
{
name: "wrong type",
plugin: 3,
expectedError: "int is not a RestoreItemActionV2!",
expectedError: "plugin int is not a RestoreItemActionV2",
},
{
name: "happy path",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func NewRestartableVolumeSnapshotter(name string, sharedPluginProcess process.Re
func (r *RestartableVolumeSnapshotter) Reinitialize(dispensed interface{}) error {
volumeSnapshotter, ok := dispensed.(vsv1.VolumeSnapshotter)
if !ok {
return errors.Errorf("%T is not a VolumeSnapshotter!", dispensed)
return errors.Errorf("plugin %T is not a VolumeSnapshotter", dispensed)
}
return r.init(volumeSnapshotter, r.config)
}
Expand All @@ -87,7 +87,7 @@ func (r *RestartableVolumeSnapshotter) getVolumeSnapshotter() (vsv1.VolumeSnapsh

volumeSnapshotter, ok := plugin.(vsv1.VolumeSnapshotter)
if !ok {
return nil, errors.Errorf("%T is not a VolumeSnapshotter!", plugin)
return nil, errors.Errorf("plugin %T is not a VolumeSnapshotter", plugin)
}

return volumeSnapshotter, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestRestartableGetVolumeSnapshotter(t *testing.T) {
{
name: "wrong type",
plugin: 3,
expectedError: "int is not a VolumeSnapshotter!",
expectedError: "plugin int is not a VolumeSnapshotter",
},
{
name: "happy path",
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestRestartableVolumeSnapshotterReinitialize(t *testing.T) {
}

err := r.Reinitialize(3)
assert.EqualError(t, err, "int is not a VolumeSnapshotter!")
assert.EqualError(t, err, "plugin int is not a VolumeSnapshotter")

volumeSnapshotter := new(providermocks.VolumeSnapshotter)
volumeSnapshotter.Test(t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ func AsyncOperationsNotSupportedError() error {
}

func InvalidOperationIDError(operationID string) error {
return errors.New(fmt.Sprintf("Operation ID %v is invalid.", operationID))
return fmt.Errorf("operation ID %v is invalid", operationID)
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ func AsyncOperationsNotSupportedError() error {
}

func InvalidOperationIDError(operationID string) error {
return errors.New(fmt.Sprintf("Operation ID %v is invalid.", operationID))
return fmt.Errorf("operation ID %v is invalid", operationID)
}
3 changes: 1 addition & 2 deletions pkg/podvolume/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,8 @@ func GetSnapshotIdentifier(podVolumeBackups *velerov1api.PodVolumeBackupList) []
func getUploaderTypeOrDefault(uploaderType string) string {
if uploaderType != "" {
return uploaderType
} else {
return uploader.ResticType
}
return uploader.ResticType
}

// getRepositoryType returns the hardcode repositoryType for different backup methods - Restic or Kopia,uploaderType
Expand Down
12 changes: 6 additions & 6 deletions pkg/repository/backup_repo_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ type BackupRepositoryKey struct {
}

var (
backupRepoNotFoundError = errors.New("backup repository not found")
backupRepoNotProvisionedError = errors.New("backup repository not provisioned")
errBackupRepoNotFound = errors.New("backup repository not found")
errBackupRepoNotProvisioned = errors.New("backup repository not provisioned")
)

func repoLabelsFromKey(key BackupRepositoryKey) labels.Set {
Expand Down Expand Up @@ -69,7 +69,7 @@ func GetBackupRepository(ctx context.Context, cli client.Client, namespace strin
}

if len(backupRepoList.Items) == 0 {
return nil, backupRepoNotFoundError
return nil, errBackupRepoNotFound
}

if len(backupRepoList.Items) > 1 {
Expand All @@ -84,7 +84,7 @@ func GetBackupRepository(ctx context.Context, cli client.Client, namespace strin
}

if repo.Status.Phase == "" || repo.Status.Phase == velerov1api.BackupRepositoryPhaseNew {
return nil, backupRepoNotProvisionedError
return nil, errBackupRepoNotProvisioned
}
}

Expand All @@ -107,9 +107,9 @@ func newBackupRepository(namespace string, key BackupRepositoryKey) *velerov1api
}

func isBackupRepositoryNotFoundError(err error) bool {
return (err == backupRepoNotFoundError)
return (err == errBackupRepoNotFound)
}

func isBackupRepositoryNotProvisionedError(err error) bool {
return (err == backupRepoNotProvisionedError)
return (err == errBackupRepoNotProvisioned)
}
3 changes: 1 addition & 2 deletions pkg/repository/config/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func GetGCPResticEnvVars(config map[string]string) (map[string]string, error) {
func GetGCPCredentials(config map[string]string) string {
if credentialsFile, ok := config[CredentialsFileKey]; ok {
return credentialsFile
} else {
return os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")
}
return os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")
}
6 changes: 2 additions & 4 deletions pkg/repository/provider/unified_repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,9 +660,8 @@ func TestPrepareRepo(t *testing.T) {
retFuncInit: func(ctx context.Context, repoOption udmrepo.RepoOptions, createNew bool) error {
if !createNew {
return nil
} else {
return errors.New("fake-error")
}
return errors.New("fake-error")
},
},
{
Expand All @@ -681,9 +680,8 @@ func TestPrepareRepo(t *testing.T) {
retFuncInit: func(ctx context.Context, repoOption udmrepo.RepoOptions, createNew bool) error {
if !createNew {
return errors.New("fake-error-1")
} else {
return errors.New("fake-error-2")
}
return errors.New("fake-error-2")
},
expectedErr: "error to init backup repo: fake-error-2",
},
Expand Down
6 changes: 2 additions & 4 deletions pkg/repository/udmrepo/kopialib/backend/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ import (
func mustHaveString(key string, flags map[string]string) (string, error) {
if value, exist := flags[key]; exist {
return value, nil
} else {
return "", errors.New("key " + key + " not found")
}
return "", errors.New("key " + key + " not found")
}

func optionalHaveString(key string, flags map[string]string) string {
Expand Down Expand Up @@ -68,9 +67,8 @@ func optionalHaveFloat64(ctx context.Context, key string, flags map[string]strin
func optionalHaveStringWithDefault(key string, flags map[string]string, defValue string) string {
if value, exist := flags[key]; exist {
return value
} else {
return defValue
}
return defValue
}

func optionalHaveDuration(ctx context.Context, key string, flags map[string]string) time.Duration {
Expand Down

0 comments on commit a22a345

Please sign in to comment.