29 lines
891 B
Go
29 lines
891 B
Go
package cmnet
|
|
|
|
import "testing"
|
|
|
|
func TestRestorePhone(t *testing.T) {
|
|
phone, err := restorePhone("138******00", "000000")
|
|
if err != nil || phone != "13800000000" {
|
|
t.Fatalf("phone %s %v", phone, err)
|
|
}
|
|
if _, err := restorePhone("138****0000", "0000"); err == nil {
|
|
t.Fatal("short code should fail")
|
|
}
|
|
}
|
|
|
|
func TestParseQRPoll(t *testing.T) {
|
|
waiting, artifact, err := parseQRPoll(nil)
|
|
if err != nil || !waiting.Waiting || artifact != "" {
|
|
t.Fatalf("empty %+v %s %v", waiting, artifact, err)
|
|
}
|
|
expired, artifact, err := parseQRPoll([]byte(`{"resultCode":"8020"}`))
|
|
if err != nil || !expired.Expired {
|
|
t.Fatalf("expired %+v %v", expired, err)
|
|
}
|
|
ok, artifact, err := parseQRPoll([]byte(`{"resultCode":"0000","artifact":"abc","resultDesc":"登录成功"}`))
|
|
if err != nil || artifact != "abc" || ok.Waiting || ok.Expired {
|
|
t.Fatalf("ok %+v %s %v", ok, artifact, err)
|
|
}
|
|
}
|