43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
package gateway
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestRealnameStatusRespUpstreamRealnameAt(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
body string
|
|
want string
|
|
}{
|
|
{"移动返回实名时间", `{"archiveTime":"2026-07-16 19:43:39","iccid":"89860885192590574640","realStatus":true}`, "2026-07-16T19:43:39+08:00"},
|
|
{"电信不返回", `{"iccid":"8986112520903884400","realStatus":true}`, ""},
|
|
{"联通 extend 无时间", `{"extend":"已实名","iccid":"89860625750010460562","realStatus":true}`, ""},
|
|
{"未实名 null", `{"archiveTime":null,"iccid":"898608851925D1284902","realStatus":false}`, ""},
|
|
{"未实名但带时间忽略", `{"archiveTime":"2026-07-16 19:43:39","realStatus":false}`, ""},
|
|
{"空串", `{"archiveTime":"","realStatus":true}`, ""},
|
|
{"格式错误", `{"archiveTime":"07/16/2026","realStatus":true}`, ""},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
var resp RealnameStatusResp
|
|
if err := json.Unmarshal([]byte(tc.body), &resp); err != nil {
|
|
t.Fatalf("unmarshal: %v", err)
|
|
}
|
|
got := resp.UpstreamRealnameAt()
|
|
if tc.want == "" {
|
|
if got != nil {
|
|
t.Fatalf("want nil, got %v", got)
|
|
}
|
|
return
|
|
}
|
|
want, _ := time.Parse(time.RFC3339, tc.want)
|
|
if got == nil || !got.Equal(want) {
|
|
t.Fatalf("want %v, got %v", want, got)
|
|
}
|
|
})
|
|
}
|
|
}
|