Files

38 lines
1.1 KiB
Go

// normalize_test.go Day55:回执状态归一化表驱动测试(Day56 消费者地基)。
package report
import "testing"
func TestNormalize(t *testing.T) {
cases := []struct {
stat string
want Status
why string
}{
{"DELIVRD", StatusSuccess, "CMPP 标准成功"},
{"delivrd", StatusSuccess, "大小写不敏感"},
{" DelIVRd ", StatusSuccess, "容忍空白"},
{"EXPIRED", StatusFailure, "消息过期"},
{"UNDELIV", StatusFailure, "无法投递"},
{"REJECTD", StatusFailure, "短信拒收"},
{"DELETED", StatusFailure, "已删除终态"},
{"", StatusUnknown, "空回执挂起"},
{"GB:0001", StatusUnknown, "中间态非终态"},
{"ID:0088", StatusUnknown, "未识别错误码挂起"},
}
for _, c := range cases {
if got := Normalize(c.stat); got != c.want {
t.Errorf("Normalize(%q)=%v want %v(%s)", c.stat, got, c.want, c.why)
}
}
}
func TestIsFinal(t *testing.T) {
if !IsFinal("DELIVRD") || !IsFinal("EXPIRED") {
t.Error("成功/失败应为终态")
}
if IsFinal("") || IsFinal("GB:0001") {
t.Error("空/中间态应非终态(挂起等补偿)")
}
}