milvus/internal/indexnode/indexnode_mock_test.go
cai.zhang e6e03fc93f
Add unittest for index component (#7475)
Signed-off-by: cai.zhang <cai.zhang@zilliz.com>
2021-09-06 17:54:41 +08:00

78 lines
2.3 KiB
Go

// Copyright (C) 2019-2020 Zilliz. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations under the License.
package indexnode
import (
"context"
"testing"
"github.com/milvus-io/milvus/internal/proto/commonpb"
"github.com/milvus-io/milvus/internal/proto/indexpb"
"github.com/milvus-io/milvus/internal/proto/internalpb"
"github.com/milvus-io/milvus/internal/proto/milvuspb"
"github.com/stretchr/testify/assert"
)
func TestIndexNodeMock(t *testing.T) {
Params.Init()
inm := Mock{}
err := inm.Register()
assert.Nil(t, err)
err = inm.Init()
assert.Nil(t, err)
err = inm.Start()
assert.Nil(t, err)
ctx := context.Background()
t.Run("GetComponentStates", func(t *testing.T) {
states, err := inm.GetComponentStates(ctx)
assert.Nil(t, err)
assert.Equal(t, internalpb.StateCode_Healthy, states.State.StateCode)
})
t.Run("GetTimeTickChannel", func(t *testing.T) {
resp, err := inm.GetTimeTickChannel(ctx)
assert.Nil(t, err)
assert.Equal(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
})
t.Run("GetStatisticsChannel", func(t *testing.T) {
resp, err := inm.GetStatisticsChannel(ctx)
assert.Nil(t, err)
assert.Equal(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
})
t.Run("CreateIndex", func(t *testing.T) {
req := &indexpb.CreateIndexRequest{
IndexBuildID: 0,
IndexID: 0,
DataPaths: []string{},
}
resp, err := inm.CreateIndex(ctx, req)
assert.Nil(t, err)
assert.Equal(t, commonpb.ErrorCode_Success, resp.ErrorCode)
})
t.Run("GetMetrics", func(t *testing.T) {
req := &milvuspb.GetMetricsRequest{
Request: "",
}
resp, err := inm.GetMetrics(ctx, req)
assert.Nil(t, err)
assert.Equal(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
assert.Equal(t, "IndexNode", resp.ComponentName)
})
err = inm.Stop()
assert.Nil(t, err)
}