提交 3c2afb20 编写于 作者: W wu.sphinx

Add test case and function rename

上级 a4cb6f95
......@@ -30,7 +30,7 @@ import (
)
const (
// https://dev.mysql.com/doc/refman/8.0/en/identifiers.html
// IndexNameMaxLength Ref. https://dev.mysql.com/doc/refman/8.0/en/identifiers.html
IndexNameMaxLength = 64
)
......@@ -562,7 +562,7 @@ func (idxAdv *IndexAdvisor) mergeIndexes(idxList []IndexInfo) []IndexInfo {
// 检测索引名称是否重复?
if existedIndexes := indexMeta.FindIndex(database.IndexKeyName, idx.Name); len(existedIndexes) > 0 {
var newName string
idxSuffix := getIndexNameSuffix()
idxSuffix := getRandomIndexSuffix()
if len(idx.Name) < IndexNameMaxLength-len(idxSuffix) {
newName = idx.Name + idxSuffix
} else {
......@@ -584,7 +584,8 @@ func (idxAdv *IndexAdvisor) mergeIndexes(idxList []IndexInfo) []IndexInfo {
return rmSelfDupIndex(indexes)
}
func getIndexNameSuffix() string {
// getRandomIndexSuffix format: _xxxx, length: 5
func getRandomIndexSuffix() string {
return fmt.Sprintf("_%s", uniuri.New()[:4])
}
......
......@@ -19,6 +19,7 @@ package advisor
import (
"fmt"
"os"
"strings"
"testing"
"github.com/XiaoMi/soar/common"
......@@ -464,3 +465,12 @@ func TestIdxColsTypeCheck(t *testing.T) {
}
}
}
func TestGetRandomIndexSuffix(t *testing.T) {
for i := 0; i < 5; i++ {
r := getRandomIndexSuffix()
if !(strings.HasPrefix(r, "_") && len(r) == 5) {
t.Errorf("getRandomIndexSuffix should return a string with prefix `_` and 5 length, but got:%s", r)
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册