Remove dependency of the legacy client code from pkg/cmd directory.

Signed-off-by: Xun Jiang <jxun@vmware.com>
This commit is contained in:
Xun Jiang
2023-07-14 15:55:09 +08:00
parent e54a8af0ad
commit 89d3ad4864
22 changed files with 330 additions and 255 deletions
+3 -10
View File
@@ -26,14 +26,11 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
factorymocks "github.com/vmware-tanzu/velero/pkg/client/mocks"
"github.com/vmware-tanzu/velero/pkg/cmd/cli"
cmdtest "github.com/vmware-tanzu/velero/pkg/cmd/test"
versionedmocks "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/mocks"
"github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/scheme"
velerotest "github.com/vmware-tanzu/velero/pkg/test"
veleroexec "github.com/vmware-tanzu/velero/pkg/util/exec"
)
@@ -41,9 +38,7 @@ func TestNewDeleteCommand(t *testing.T) {
// create a factory
f := &factorymocks.Factory{}
client := &versionedmocks.Interface{}
kbclient := fake.NewClientBuilder().WithScheme(scheme.Scheme).Build()
f.On("Client").Return(client, nil)
kbclient := velerotest.NewFakeControllerRuntimeClient(t)
f.On("Namespace").Return(mock.Anything)
f.On("KubebuilderClient").Return(kbclient, nil)
@@ -86,9 +81,7 @@ func TestDeleteFunctions(t *testing.T) {
//t.Run("create the other create command with fromSchedule option for Run() other branches", func(t *testing.T) {
// create a factory
f := &factorymocks.Factory{}
client := &versionedmocks.Interface{}
kbclient := fake.NewClientBuilder().WithScheme(scheme.Scheme).Build()
f.On("Client").Return(client, nil)
kbclient := velerotest.NewFakeControllerRuntimeClient(t)
f.On("Namespace").Return(mock.Anything)
f.On("KubebuilderClient").Return(kbclient, nil)
+2 -3
View File
@@ -24,11 +24,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
factorymocks "github.com/vmware-tanzu/velero/pkg/client/mocks"
cmdtest "github.com/vmware-tanzu/velero/pkg/cmd/test"
"github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/scheme"
velerotest "github.com/vmware-tanzu/velero/pkg/test"
veleroexec "github.com/vmware-tanzu/velero/pkg/util/exec"
)
@@ -36,7 +35,7 @@ func TestNewGetCommand(t *testing.T) {
bkList := []string{"b1", "b2"}
f := &factorymocks.Factory{}
kbclient := fake.NewClientBuilder().WithScheme(scheme.Scheme).Build()
kbclient := velerotest.NewFakeControllerRuntimeClient(t)
f.On("Namespace").Return(mock.Anything)
f.On("KubebuilderClient").Return(kbclient, nil)