mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-04 09:52:30 +08:00
relate: https://github.com/milvus-io/milvus/issues/35853 https://github.com/milvus-io/milvus/issues/36751 --------- Signed-off-by: aoiasd <zhicheng.yue@zilliz.com>
74 lines
1.8 KiB
Go
74 lines
1.8 KiB
Go
package ctokenizer
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
|
|
)
|
|
|
|
func TestValidateEmptyTextSchema(t *testing.T) {
|
|
fs := &schemapb.FieldSchema{
|
|
FieldID: 101,
|
|
DataType: schemapb.DataType_VarChar,
|
|
TypeParams: []*commonpb.KeyValuePair{},
|
|
}
|
|
assert.Nil(t, ValidateTextSchema(fs))
|
|
}
|
|
|
|
func TestValidateTextSchema(t *testing.T) {
|
|
tests := []*schemapb.FieldSchema{
|
|
{
|
|
FieldID: 101,
|
|
DataType: schemapb.DataType_VarChar,
|
|
TypeParams: []*commonpb.KeyValuePair{
|
|
{Key: "enable_match", Value: "true"},
|
|
},
|
|
},
|
|
{
|
|
FieldID: 101,
|
|
DataType: schemapb.DataType_VarChar,
|
|
TypeParams: []*commonpb.KeyValuePair{
|
|
{Key: "enable_match", Value: "true"},
|
|
{Key: "tokenizer_params", Value: `{"tokenizer": "standard"}`},
|
|
},
|
|
},
|
|
{
|
|
FieldID: 101,
|
|
DataType: schemapb.DataType_VarChar,
|
|
TypeParams: []*commonpb.KeyValuePair{
|
|
{Key: "enable_match", Value: "true"},
|
|
{Key: "tokenizer_params", Value: `{"tokenizer": "standard"}`},
|
|
},
|
|
},
|
|
}
|
|
|
|
for idx, tt := range tests {
|
|
t.Run(fmt.Sprintf("enable_tokenizer not set %d", idx), func(t *testing.T) {
|
|
err := ValidateTextSchema(tt)
|
|
assert.NotNil(t, err)
|
|
})
|
|
}
|
|
|
|
for idx, tt := range tests {
|
|
t.Run(fmt.Sprintf("enable_tokenizer set to false %d", idx), func(t *testing.T) {
|
|
tt.TypeParams = append(tt.TypeParams, &commonpb.KeyValuePair{
|
|
Key: "enable_tokenizer",
|
|
Value: "false",
|
|
})
|
|
err := ValidateTextSchema(tt)
|
|
assert.NotNil(t, err)
|
|
})
|
|
}
|
|
for idx, tt := range tests {
|
|
t.Run(fmt.Sprintf("enable_tokenizer set to true %d", idx), func(t *testing.T) {
|
|
tt.TypeParams[len(tt.TypeParams)-1].Value = "true"
|
|
err := ValidateTextSchema(tt)
|
|
assert.Nil(t, err)
|
|
})
|
|
}
|
|
}
|