2022-07-22 02:20:29 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2022-10-16 12:49:27 +00:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/commonpb"
|
2022-08-25 07:48:54 +00:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/indexpb"
|
2022-07-22 02:20:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2022-08-23 02:44:52 +00:00
|
|
|
indexID int64 = 1
|
|
|
|
indexName = "idx"
|
|
|
|
indexParams = []*commonpb.KeyValuePair{
|
2022-07-22 02:20:29 +00:00
|
|
|
{
|
|
|
|
Key: "field110-i1",
|
|
|
|
Value: "field110-v1",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
indexModel = &Index{
|
|
|
|
IndexID: indexID,
|
|
|
|
IndexName: indexName,
|
|
|
|
IndexParams: indexParams,
|
|
|
|
IsDeleted: true,
|
|
|
|
CreateTime: 1,
|
|
|
|
}
|
|
|
|
|
2022-08-25 07:48:54 +00:00
|
|
|
indexPb = &indexpb.FieldIndex{
|
|
|
|
IndexInfo: &indexpb.IndexInfo{
|
|
|
|
CollectionID: colID,
|
|
|
|
FieldID: fieldID,
|
|
|
|
IndexName: indexName,
|
|
|
|
IndexID: indexID,
|
|
|
|
TypeParams: typeParams,
|
|
|
|
IndexParams: indexParams,
|
|
|
|
},
|
|
|
|
Deleted: true,
|
|
|
|
CreateTime: 1,
|
2022-07-22 02:20:29 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMarshalIndexModel(t *testing.T) {
|
|
|
|
ret := MarshalIndexModel(indexModel)
|
2022-08-25 07:48:54 +00:00
|
|
|
assert.Equal(t, indexPb.IndexInfo.IndexID, ret.IndexInfo.IndexID)
|
2022-07-22 02:20:29 +00:00
|
|
|
assert.Nil(t, MarshalIndexModel(nil))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUnmarshalIndexModel(t *testing.T) {
|
|
|
|
ret := UnmarshalIndexModel(indexPb)
|
2022-08-25 07:48:54 +00:00
|
|
|
assert.Equal(t, indexModel.IndexID, ret.IndexID)
|
2022-07-22 02:20:29 +00:00
|
|
|
assert.Nil(t, UnmarshalIndexModel(nil))
|
|
|
|
}
|