forked from haofree/opendmm-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opendmm_test.go
54 lines (49 loc) · 1.08 KB
/
opendmm_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
package opendmm
import (
"sync"
"testing"
"github.com/benbjohnson/phantomjs"
)
func TestOpendmmSearch(t *testing.T) {
phantomjs.DefaultProcess.Open()
defer phantomjs.DefaultProcess.Close()
queries := []string{
"SDDE-201",
"200GANA-894",
"3DSVR-106",
}
wg := new(sync.WaitGroup)
for _, query := range queries {
wg.Add(1)
go func(query string) {
defer wg.Done()
for attempt, maxAttempt := 1, 5; ; attempt++ {
metach := Search(query)
meta, ok := <-metach
if ok {
t.Logf("%s -> %+v", query, meta)
break
}
if attempt < maxAttempt {
t.Logf("Attempt #%d failed for %s", attempt, query)
} else {
t.Fatalf("All %d attempts failed for %s", maxAttempt, query)
}
}
}(query)
}
wg.Wait()
}
func TestOpendmmGuess(t *testing.T) {
queries := []string{
"SDDE-201",
}
for _, query := range queries {
if !Guess(query + "_suffix").Contains(query) {
t.Fatalf("Guessed wrong code for %s with suffix", query)
}
if !Guess("prefix_" + query).Contains(query) {
t.Fatalf("Guessed wrong code for %s with prefix", query)
}
}
}