Fix index ut (#32957)

Signed-off-by: Cai Zhang <cai.zhang@zilliz.com>
lru-dev
cai.zhang 2024-05-11 11:36:53 +08:00 committed by GitHub
parent 7d6a76088b
commit 3943a96d6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 37 additions and 2 deletions

View File

@ -21,13 +21,15 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
"github.com/milvus-io/milvus/internal/indexnode"
"github.com/milvus-io/milvus/internal/mocks"
"github.com/milvus-io/milvus/internal/proto/indexpb"
"github.com/milvus-io/milvus/internal/proto/internalpb"
"github.com/milvus-io/milvus/internal/util/dependency"
"github.com/milvus-io/milvus/pkg/util/merr"
"github.com/milvus-io/milvus/pkg/util/metricsinfo"
"github.com/milvus-io/milvus/pkg/util/paramtable"
)
@ -40,7 +42,13 @@ func TestIndexNodeServer(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, server)
inm := indexnode.NewIndexNodeMock()
inm := mocks.NewMockIndexNode(t)
inm.EXPECT().SetEtcdClient(mock.Anything).Return()
inm.EXPECT().SetAddress(mock.Anything).Return()
inm.EXPECT().Start().Return(nil)
inm.EXPECT().Init().Return(nil)
inm.EXPECT().Register().Return(nil)
inm.EXPECT().Stop().Return(nil)
err = server.setServer(inm)
assert.NoError(t, err)
@ -48,6 +56,11 @@ func TestIndexNodeServer(t *testing.T) {
assert.NoError(t, err)
t.Run("GetComponentStates", func(t *testing.T) {
inm.EXPECT().GetComponentStates(mock.Anything, mock.Anything).Return(&milvuspb.ComponentStates{
State: &milvuspb.ComponentInfo{
StateCode: commonpb.StateCode_Healthy,
},
}, nil)
req := &milvuspb.GetComponentStatesRequest{}
states, err := server.GetComponentStates(ctx, req)
assert.NoError(t, err)
@ -55,6 +68,9 @@ func TestIndexNodeServer(t *testing.T) {
})
t.Run("GetStatisticsChannel", func(t *testing.T) {
inm.EXPECT().GetStatisticsChannel(mock.Anything, mock.Anything).Return(&milvuspb.StringResponse{
Status: merr.Success(),
}, nil)
req := &internalpb.GetStatisticsChannelRequest{}
resp, err := server.GetStatisticsChannel(ctx, req)
assert.NoError(t, err)
@ -62,6 +78,7 @@ func TestIndexNodeServer(t *testing.T) {
})
t.Run("CreateJob", func(t *testing.T) {
inm.EXPECT().CreateJob(mock.Anything, mock.Anything).Return(merr.Success(), nil)
req := &indexpb.CreateJobRequest{
ClusterID: "",
BuildID: 0,
@ -74,6 +91,9 @@ func TestIndexNodeServer(t *testing.T) {
})
t.Run("QueryJob", func(t *testing.T) {
inm.EXPECT().QueryJobs(mock.Anything, mock.Anything).Return(&indexpb.QueryJobsResponse{
Status: merr.Success(),
}, nil)
req := &indexpb.QueryJobsRequest{}
resp, err := server.QueryJobs(ctx, req)
assert.NoError(t, err)
@ -81,6 +101,7 @@ func TestIndexNodeServer(t *testing.T) {
})
t.Run("DropJobs", func(t *testing.T) {
inm.EXPECT().DropJobs(mock.Anything, mock.Anything).Return(merr.Success(), nil)
req := &indexpb.DropJobsRequest{}
resp, err := server.DropJobs(ctx, req)
assert.NoError(t, err)
@ -88,6 +109,9 @@ func TestIndexNodeServer(t *testing.T) {
})
t.Run("ShowConfigurations", func(t *testing.T) {
inm.EXPECT().ShowConfigurations(mock.Anything, mock.Anything).Return(&internalpb.ShowConfigurationsResponse{
Status: merr.Success(),
}, nil)
req := &internalpb.ShowConfigurationsRequest{
Pattern: "",
}
@ -97,6 +121,9 @@ func TestIndexNodeServer(t *testing.T) {
})
t.Run("GetMetrics", func(t *testing.T) {
inm.EXPECT().GetMetrics(mock.Anything, mock.Anything).Return(&milvuspb.GetMetricsResponse{
Status: merr.Success(),
}, nil)
req, err := metricsinfo.ConstructRequestByMetricType(metricsinfo.SystemInfoMetrics)
assert.NoError(t, err)
resp, err := server.GetMetrics(ctx, req)
@ -105,6 +132,9 @@ func TestIndexNodeServer(t *testing.T) {
})
t.Run("GetTaskSlots", func(t *testing.T) {
inm.EXPECT().GetJobStats(mock.Anything, mock.Anything).Return(&indexpb.GetJobStatsResponse{
Status: merr.Success(),
}, nil)
req := &indexpb.GetJobStatsRequest{}
resp, err := server.GetJobStats(ctx, req)
assert.NoError(t, err)
@ -112,6 +142,7 @@ func TestIndexNodeServer(t *testing.T) {
})
t.Run("CreateJobV2", func(t *testing.T) {
inm.EXPECT().CreateJobV2(mock.Anything, mock.Anything).Return(merr.Success(), nil)
req := &indexpb.CreateJobV2Request{}
resp, err := server.CreateJobV2(ctx, req)
assert.NoError(t, err)
@ -119,6 +150,9 @@ func TestIndexNodeServer(t *testing.T) {
})
t.Run("QueryJobsV2", func(t *testing.T) {
inm.EXPECT().QueryJobsV2(mock.Anything, mock.Anything).Return(&indexpb.QueryJobsV2Response{
Status: merr.Success(),
}, nil)
req := &indexpb.QueryJobsV2Request{}
resp, err := server.QueryJobsV2(ctx, req)
assert.NoError(t, err)
@ -126,6 +160,7 @@ func TestIndexNodeServer(t *testing.T) {
})
t.Run("DropJobsV2", func(t *testing.T) {
inm.EXPECT().DropJobsV2(mock.Anything, mock.Anything).Return(merr.Success(), nil)
req := &indexpb.DropJobsV2Request{}
resp, err := server.DropJobsV2(ctx, req)
assert.NoError(t, err)