neza2017 a250eb370f Check request type and add unittest
Signed-off-by: neza2017 <yefu.chen@zilliz.com>
2021-04-08 15:26:18 +08:00

60 lines
1.1 KiB
Go

package masterservice
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
"github.com/zilliztech/milvus-distributed/internal/proto/etcdpb"
"github.com/zilliztech/milvus-distributed/internal/proto/schemapb"
)
func TestEqualKeyPairArray(t *testing.T) {
p1 := []*commonpb.KeyValuePair{
{
Key: "k1",
Value: "v1",
},
}
p2 := []*commonpb.KeyValuePair{}
assert.False(t, EqualKeyPairArray(p1, p2))
p2 = append(p2, &commonpb.KeyValuePair{
Key: "k2",
Value: "v2",
})
assert.False(t, EqualKeyPairArray(p1, p2))
p2 = []*commonpb.KeyValuePair{
{
Key: "k1",
Value: "v2",
},
}
assert.False(t, EqualKeyPairArray(p1, p2))
p2 = []*commonpb.KeyValuePair{
{
Key: "k1",
Value: "v1",
},
}
assert.True(t, EqualKeyPairArray(p1, p2))
}
func Test_GetFieldSchemaByID(t *testing.T) {
coll := &etcdpb.CollectionInfo{
Schema: &schemapb.CollectionSchema{
Fields: []*schemapb.FieldSchema{
{
FieldID: 1,
},
},
},
}
_, err := GetFieldSchemaByID(coll, 1)
assert.Nil(t, err)
_, err = GetFieldSchemaByID(coll, 2)
assert.NotNil(t, err)
}