chore(init): 初始化解忧商行项目并完成 Phase 0 基座
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package csmanualentry
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNormalizeEntryNo(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
want string
|
||||
wantErr error
|
||||
}{
|
||||
{name: "trim", input: " 202610120013 ", want: "202610120013"},
|
||||
{name: "plain", input: "202610120013", want: "202610120013"},
|
||||
{name: "empty", input: " ", wantErr: ErrEntryNoInvalid},
|
||||
{name: "inner space", input: "2026 1001", wantErr: ErrEntryNoInvalid},
|
||||
{name: "too long", input: strings.Repeat("1", 65), wantErr: ErrEntryNoInvalid},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := normalizeEntryNo(tt.input)
|
||||
if !errors.Is(err, tt.wantErr) {
|
||||
t.Fatalf("normalizeEntryNo(%q) error = %v, want %v", tt.input, err, tt.wantErr)
|
||||
}
|
||||
if tt.wantErr == nil && got != tt.want {
|
||||
t.Fatalf("normalizeEntryNo(%q) = %q, want %q", tt.input, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsDuplicateEntry(t *testing.T) {
|
||||
if isDuplicateEntry(nil) {
|
||||
t.Fatal("nil should not be duplicate")
|
||||
}
|
||||
if !isDuplicateEntry(errors.New("Error 1062 (23000): Duplicate entry")) {
|
||||
t.Fatal("1062 error should be duplicate")
|
||||
}
|
||||
if isDuplicateEntry(errors.New("some other error")) {
|
||||
t.Fatal("unrelated error should not be duplicate")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user