mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-02 11:59:00 +08:00
24b29bec30
Signed-off-by: sunby <bingyi.sun@zilliz.com>
85 lines
1.6 KiB
Go
85 lines
1.6 KiB
Go
package proxy
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestValidateCollectionName(t *testing.T) {
|
|
Params.Init()
|
|
assert.Nil(t, ValidateCollectionName("abc"))
|
|
assert.Nil(t, ValidateCollectionName("_123abc"))
|
|
assert.Nil(t, ValidateCollectionName("abc123_$"))
|
|
|
|
longName := make([]byte, 256)
|
|
for i := 0; i < len(longName); i++ {
|
|
longName[i] = 'a'
|
|
}
|
|
invalidNames := []string{
|
|
"123abc",
|
|
"$abc",
|
|
"_12 ac",
|
|
" ",
|
|
"",
|
|
string(longName),
|
|
"中文",
|
|
}
|
|
|
|
for _, name := range invalidNames {
|
|
assert.NotNil(t, ValidateCollectionName(name))
|
|
}
|
|
}
|
|
|
|
func TestValidatePartitionTag(t *testing.T) {
|
|
Params.Init()
|
|
assert.Nil(t, ValidatePartitionTag("abc", true))
|
|
assert.Nil(t, ValidatePartitionTag("_123abc", true))
|
|
assert.Nil(t, ValidatePartitionTag("abc123_$", true))
|
|
|
|
longName := make([]byte, 256)
|
|
for i := 0; i < len(longName); i++ {
|
|
longName[i] = 'a'
|
|
}
|
|
invalidNames := []string{
|
|
"123abc",
|
|
"$abc",
|
|
"_12 ac",
|
|
" ",
|
|
"",
|
|
string(longName),
|
|
"中文",
|
|
}
|
|
|
|
for _, name := range invalidNames {
|
|
assert.NotNil(t, ValidatePartitionTag(name, true))
|
|
}
|
|
|
|
assert.Nil(t, ValidatePartitionTag("ab cd", false))
|
|
assert.Nil(t, ValidatePartitionTag("ab*", false))
|
|
}
|
|
|
|
func TestValidateFieldName(t *testing.T) {
|
|
Params.Init()
|
|
assert.Nil(t, ValidateFieldName("abc"))
|
|
assert.Nil(t, ValidateFieldName("_123abc"))
|
|
|
|
longName := make([]byte, 256)
|
|
for i := 0; i < len(longName); i++ {
|
|
longName[i] = 'a'
|
|
}
|
|
invalidNames := []string{
|
|
"123abc",
|
|
"$abc",
|
|
"_12 ac",
|
|
" ",
|
|
"",
|
|
string(longName),
|
|
"中文",
|
|
}
|
|
|
|
for _, name := range invalidNames {
|
|
assert.NotNil(t, ValidateFieldName(name))
|
|
}
|
|
}
|