66 lines
1.3 KiB
Go
66 lines
1.3 KiB
Go
package unicom
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestLiveDiscover(t *testing.T) {
|
|
if os.Getenv("CU_LIVE") == "" {
|
|
t.Skip()
|
|
}
|
|
client, err := New()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ctx, cancel := context.WithTimeout(context.Background(), 70*time.Second)
|
|
defer cancel()
|
|
if err := client.Prepare(ctx); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
script, appID := client.Captcha()
|
|
if script == "" || appID == "" {
|
|
t.Fatalf("captcha script=%q app=%q", script, appID)
|
|
}
|
|
client.mu.Lock()
|
|
err = client.prepareBill(ctx)
|
|
fee, plan := client.fee.URL, client.plan.URL
|
|
version := client.fee.Version
|
|
client.mu.Unlock()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if fee == "" || plan == "" || version == "" {
|
|
t.Fatalf("fee=%s plan=%s version=%s", fee, plan, version)
|
|
}
|
|
t.Logf("captcha app %s fee %s plan %s", appID, fee, plan)
|
|
}
|
|
|
|
func TestLiveQRPoll(t *testing.T) {
|
|
if os.Getenv("CU_LIVE") == "" {
|
|
t.Skip()
|
|
}
|
|
client, err := New()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ctx, cancel := context.WithTimeout(context.Background(), 40*time.Second)
|
|
defer cancel()
|
|
img, _, err := client.QRCode(ctx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(img) < 100 {
|
|
t.Fatalf("qr %d", len(img))
|
|
}
|
|
status, err := client.PollQR(ctx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !status.Waiting {
|
|
t.Fatalf("status %#v", status)
|
|
}
|
|
}
|