-
Notifications
You must be signed in to change notification settings - Fork 3
/
solver_test.go
61 lines (49 loc) · 1.3 KB
/
solver_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package rucaptcha
import "testing"
var solver *CaptchaSolver
var lastCaptchaID *string
func TestNew(t *testing.T) {
solver = New("rucaptcha api key")
if solver == nil {
t.Errorf("Could not create solver instance\n")
}
}
func TestLoadFile(t *testing.T) {
solver.ImagePath = "./test/captcha.jpg"
data, err := solver.loadCaptchaImage()
if err != nil {
t.Errorf("Load file from disk error: %s\n", err)
}
if data != nil && len(*data) <= 0 {
t.Errorf("Load file from disk: Data too small\n")
}
solver.ImagePath = "https://raw.githubusercontent.com/allush/go-rucaptha/master/test/captcha.jpg"
data, err = solver.loadCaptchaImage()
if err != nil {
t.Errorf("Load file from url error: %s\n", err)
}
if data != nil && len(*data) <= 0 {
t.Errorf("Load file from url: Data too small\n")
}
}
func TestSolve(t *testing.T) {
solver.IsRegsence = true
answer, _, err := solver.Solve(solver.ImagePath)
if err != nil {
t.Errorf("Solve error: %s\n", err)
}
want := "8AnF"
if *answer != want {
t.Errorf("Answer(%s) not equal want(%s)\n", *answer, want)
}
}
func TestComlpain(t *testing.T) {
_, lastCaptchaID, err := solver.Solve(solver.ImagePath)
if err != nil {
t.Errorf("Solve error: %s\n", err)
}
err = solver.Complain(*lastCaptchaID)
if err != nil {
t.Errorf("Complain error: %s\n", err)
}
}