-
Notifications
You must be signed in to change notification settings - Fork 0
/
goepana_test.go
112 lines (89 loc) · 2.37 KB
/
goepana_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package gopeana
import (
"fmt"
"os"
"testing"
"time"
)
var apiKey = os.Getenv("APIKEY")
var getRequests = []string{"mona+lisa", "tierstimmenarchiv"}
func checkErr(t *testing.T, err error) {
t.Helper()
if err != nil {
t.Error(err)
}
}
func TestApiKey(t *testing.T) {
if apiKey == "" {
t.Errorf("APIKEY is empty")
}
}
func TestGetBasicSearchRequest(t *testing.T) {
c := NewClient(apiKey, "")
r, err := NewBasicSearchRequest(c, "", "", "", "")
t.Run("Creating BasicSearchRequest", func(t *testing.T) {
checkErr(t, err)
})
for _, query := range getRequests {
t.Run(fmt.Sprintf("Running GET with '%s'", query), func(t *testing.T) {
for _, re := range []string{"open"} {
for _, pr := range []string{"minimal"} {
for _, ro := range []string{""} {
for _, st := range []string{""} {
err := r.Reusability(re)
checkErr(t, err)
err = r.Profile(pr)
checkErr(t, err)
err = r.Rows(ro)
checkErr(t, err)
err = r.Start(st)
checkErr(t, err)
resp, err := Get(r, query)
checkErr(t, err)
if !resp.Success {
t.Errorf("resp.Success should be true. resp.Error = %s", resp.Error)
}
if resp.Error != "" {
t.Errorf("resp.Error should be empty. resp.Error = %s", resp.Error)
}
// Sleeping between requests because we're nice
time.Sleep(500 * time.Millisecond)
}
}
}
}
})
}
}
func TestGetCursorSearchRequest(t *testing.T) {
c := NewClient(apiKey, "")
r, err := NewCursorSearchRequest(c, "", "", "")
t.Run("Creating CursorSearchRequest", func(t *testing.T) {
checkErr(t, err)
})
for _, query := range getRequests {
t.Run(fmt.Sprintf("Running GET with '%s'", query), func(t *testing.T) {
for _, re := range []string{"open"} {
for _, pr := range []string{"minimal"} {
for _, cu := range []string{""} {
err := r.Reusability(re)
checkErr(t, err)
err = r.Profile(pr)
checkErr(t, err)
resp, err := Get(r, query)
checkErr(t, err)
r.Cursor(cu)
if !resp.Success {
t.Errorf("resp.Success should be true. resp.Error = %s", resp.Error)
}
if resp.Error != "" {
t.Errorf("resp.Error should be empty. resp.Error = %s", resp.Error)
}
// Sleeping between requests because we're nice
time.Sleep(500 * time.Millisecond)
}
}
}
})
}
}