sync: 同步 v1.0.4 开源代码并脱敏
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package batchfields
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
func TestItemIDRejectsOversizedCardIdentifier(t *testing.T) {
|
||||
if got := ItemID(strings.Repeat("9", 65)); got != "" {
|
||||
t.Fatalf("oversized identifier = %q, want empty", got)
|
||||
}
|
||||
if got := ItemID(strings.Repeat("9", 64)); len(got) != 64 {
|
||||
t.Fatalf("64-character identifier = %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetailReasonFitsColumn(t *testing.T) {
|
||||
if got := DetailReason(strings.Repeat("错", 513)); utf8.RuneCountInString(got) != 512 {
|
||||
t.Fatalf("detail reason length = %d", utf8.RuneCountInString(got))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFailureReasonOmitsStatementAndFitsColumn(t *testing.T) {
|
||||
value := "insert failed: INSERT INTO batch_detail VALUES (" + strings.Repeat("错", 30000) + ")"
|
||||
got := FailureReason(value)
|
||||
if strings.Contains(got, "VALUES") || len(got) > FailureReasonByteLimit || !utf8.ValidString(got) {
|
||||
t.Fatalf("unsafe failure reason: %q", got)
|
||||
}
|
||||
got = FailureReason(strings.Repeat("错", 30000))
|
||||
if len(got) > FailureReasonByteLimit || !utf8.ValidString(got) {
|
||||
t.Fatalf("invalid truncated UTF-8 reason")
|
||||
}
|
||||
got = FailureReason("insert detail failed: INSERT INTO batch_detail VALUES ('" + strings.Repeat("9", 1000) + "'): Error 1406 (22001): Data too long for column 'item_id' at row 1")
|
||||
if strings.Contains(got, "VALUES") || !strings.Contains(got, "Error 1406 (22001)") {
|
||||
t.Fatalf("SQL should be removed but database error preserved: %q", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user