Skip to content

Commit

Permalink
Hide testify in internal
Browse files Browse the repository at this point in the history
  • Loading branch information
ykadowak committed Feb 20, 2024
1 parent 034b25b commit dd84674
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
5 changes: 5 additions & 0 deletions internal/k8s/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -52,6 +53,9 @@ type (
MatchingLabels = cli.MatchingLabels
InNamespace = cli.InNamespace
VolumeSnapshot = snapshotv1.VolumeSnapshot
Deployment = appsv1.Deployment
DeploymentList = appsv1.DeploymentList
ObjectMeta = metav1.ObjectMeta
)

const (
Expand All @@ -64,6 +68,7 @@ const (
var (
ServerSideApply = cli.Apply
MergePatch = cli.Merge
NewSelector = labels.NewSelector
)

type Client interface {
Expand Down
13 changes: 13 additions & 0 deletions internal/test/testify/testify.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package testify

import (
"github.com/stretchr/testify/mock"
)

type (
Arguments = mock.Arguments
)

const (
Anything = mock.Anything
)
19 changes: 8 additions & 11 deletions pkg/index/job/readreplica/rotate/service/rotator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
},
Expand Down

0 comments on commit dd84674

Please sign in to comment.