From dd84674023b35bcaf954e581b5c2a38baa6a23f9 Mon Sep 17 00:00:00 2001 From: "yusuke.kadowaki" Date: Tue, 20 Feb 2024 16:33:43 +0900 Subject: [PATCH] Hide testify in internal --- internal/k8s/client/client.go | 5 +++++ internal/test/testify/testify.go | 13 +++++++++++++ .../rotate/service/rotator_test.go | 19 ++++++++----------- 3 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 internal/test/testify/testify.go diff --git a/internal/k8s/client/client.go b/internal/k8s/client/client.go index c2bbd6f96b..1efcdf1915 100644 --- a/internal/k8s/client/client.go +++ b/internal/k8s/client/client.go @@ -23,6 +23,7 @@ import ( snapshotv1 "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1" "github.com/vdaas/vald/internal/errors" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -52,6 +53,9 @@ type ( MatchingLabels = cli.MatchingLabels InNamespace = cli.InNamespace VolumeSnapshot = snapshotv1.VolumeSnapshot + Deployment = appsv1.Deployment + DeploymentList = appsv1.DeploymentList + ObjectMeta = metav1.ObjectMeta ) const ( @@ -64,6 +68,7 @@ const ( var ( ServerSideApply = cli.Apply MergePatch = cli.Merge + NewSelector = labels.NewSelector ) type Client interface { diff --git a/internal/test/testify/testify.go b/internal/test/testify/testify.go new file mode 100644 index 0000000000..dae8031a81 --- /dev/null +++ b/internal/test/testify/testify.go @@ -0,0 +1,13 @@ +package testify + +import ( + "github.com/stretchr/testify/mock" +) + +type ( + Arguments = mock.Arguments +) + +const ( + Anything = mock.Anything +) diff --git a/pkg/index/job/readreplica/rotate/service/rotator_test.go b/pkg/index/job/readreplica/rotate/service/rotator_test.go index f47e479a57..e4558eab41 100644 --- a/pkg/index/job/readreplica/rotate/service/rotator_test.go +++ b/pkg/index/job/readreplica/rotate/service/rotator_test.go @@ -16,15 +16,11 @@ package service import ( "testing" - tmock "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" "github.com/vdaas/vald/internal/errors" "github.com/vdaas/vald/internal/k8s/client" "github.com/vdaas/vald/internal/test/mock/k8s" - - appsv1 "k8s.io/api/apps/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" + "github.com/vdaas/vald/internal/test/testify" ) func Test_getNewBaseName(t *testing.T) { @@ -140,19 +136,20 @@ func Test_parseReplicaID(t *testing.T) { wantId1 := "bar" wantId2 := "baz" mock := &k8s.ValdK8sClientMock{} - mock.On("LabelSelector", tmock.Anything, tmock.Anything, tmock.Anything).Return(labels.NewSelector(), nil) - mock.On("List", tmock.Anything, tmock.Anything, tmock.Anything).Run(func(args tmock.Arguments) { - if depList, ok := args.Get(1).(*appsv1.DeploymentList); ok { - depList.Items = []appsv1.Deployment{ + + mock.On("LabelSelector", testify.Anything, testify.Anything, testify.Anything).Return(client.NewSelector(), nil) + mock.On("List", testify.Anything, testify.Anything, testify.Anything).Run(func(args testify.Arguments) { + if depList, ok := args.Get(1).(*client.DeploymentList); ok { + depList.Items = []client.Deployment{ { - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: client.ObjectMeta{ Labels: map[string]string{ labelKey: wantId1, }, }, }, { - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: client.ObjectMeta{ Labels: map[string]string{ labelKey: wantId2, },