2022-07-22 10:20:29 +08:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2022-10-16 20:49:27 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/commonpb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/schemapb"
|
2022-07-22 10:20:29 +08:00
|
|
|
pb "github.com/milvus-io/milvus/internal/proto/etcdpb"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2022-08-23 10:44:52 +08:00
|
|
|
colID int64 = 1
|
|
|
|
colName = "c"
|
|
|
|
fieldID int64 = 101
|
|
|
|
fieldName = "field110"
|
|
|
|
partID int64 = 20
|
|
|
|
partName = "testPart"
|
|
|
|
tenantID = "tenant-1"
|
|
|
|
typeParams = []*commonpb.KeyValuePair{
|
2022-07-22 10:20:29 +08:00
|
|
|
{
|
|
|
|
Key: "field110-k1",
|
|
|
|
Value: "field110-v1",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
startPositions = []*commonpb.KeyDataPair{
|
|
|
|
{
|
|
|
|
Key: "k1",
|
|
|
|
Data: []byte{byte(1)},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
colModel = &Collection{
|
2022-08-25 15:48:54 +08:00
|
|
|
TenantID: tenantID,
|
|
|
|
CollectionID: colID,
|
|
|
|
Name: colName,
|
|
|
|
AutoID: false,
|
|
|
|
Description: "none",
|
|
|
|
Fields: []*Field{fieldModel},
|
2022-07-22 10:20:29 +08:00
|
|
|
VirtualChannelNames: []string{"vch"},
|
|
|
|
PhysicalChannelNames: []string{"pch"},
|
|
|
|
ShardsNum: 1,
|
|
|
|
CreateTime: 1,
|
|
|
|
StartPositions: startPositions,
|
|
|
|
ConsistencyLevel: commonpb.ConsistencyLevel_Strong,
|
|
|
|
Partitions: []*Partition{
|
|
|
|
{
|
|
|
|
PartitionID: partID,
|
|
|
|
PartitionName: partName,
|
|
|
|
PartitionCreatedTimestamp: 1,
|
|
|
|
},
|
|
|
|
},
|
2022-10-10 20:31:22 +08:00
|
|
|
Properties: []*commonpb.KeyValuePair{
|
|
|
|
{
|
|
|
|
Key: "k",
|
|
|
|
Value: "v",
|
|
|
|
},
|
|
|
|
},
|
2022-07-22 10:20:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
deprecatedColPb = &pb.CollectionInfo{
|
|
|
|
ID: colID,
|
|
|
|
Schema: &schemapb.CollectionSchema{
|
|
|
|
Name: colName,
|
|
|
|
Description: "none",
|
|
|
|
AutoID: false,
|
|
|
|
Fields: []*schemapb.FieldSchema{filedSchemaPb},
|
|
|
|
},
|
|
|
|
CreateTime: 1,
|
|
|
|
PartitionIDs: []int64{partID},
|
|
|
|
PartitionNames: []string{partName},
|
|
|
|
PartitionCreatedTimestamps: []uint64{1},
|
|
|
|
FieldIndexes: []*pb.FieldIndexInfo{
|
|
|
|
{
|
|
|
|
FiledID: fieldID,
|
|
|
|
IndexID: indexID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
VirtualChannelNames: []string{"vch"},
|
|
|
|
PhysicalChannelNames: []string{"pch"},
|
|
|
|
ShardsNum: 1,
|
|
|
|
StartPositions: startPositions,
|
|
|
|
ConsistencyLevel: commonpb.ConsistencyLevel_Strong,
|
2022-10-10 20:31:22 +08:00
|
|
|
Properties: []*commonpb.KeyValuePair{
|
|
|
|
{
|
|
|
|
Key: "k",
|
|
|
|
Value: "v",
|
|
|
|
},
|
|
|
|
},
|
2022-07-22 10:20:29 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUnmarshalCollectionModel(t *testing.T) {
|
|
|
|
ret := UnmarshalCollectionModel(deprecatedColPb)
|
|
|
|
ret.TenantID = tenantID
|
|
|
|
assert.Equal(t, ret, colModel)
|
|
|
|
|
|
|
|
assert.Nil(t, UnmarshalCollectionModel(nil))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMarshalCollectionModel(t *testing.T) {
|
|
|
|
assert.Nil(t, MarshalCollectionModel(nil))
|
|
|
|
}
|