-
Notifications
You must be signed in to change notification settings - Fork 6
/
safer_test.go
79 lines (69 loc) · 1.65 KB
/
safer_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
package safer
import (
"testing"
"github.com/antchfx/htmlquery"
)
func TestNewClient(t *testing.T) {
c := NewClient()
if c == nil {
t.Error("expected client to not be nil but it was")
}
}
func TestClient_GetCompanyByDOTNumber(t *testing.T) {
s := newTestServer()
defer s.Close()
c := &Client{
scraper: scraper{
companySnapshotURL: s.URL + "/snapshot",
searchURL: s.URL + "/search",
},
}
snapshot, err := c.GetCompanyByDOTNumber("")
if snapshot == nil {
t.Error("snapshot returned nil")
}
if err != nil {
t.Errorf("error expected nil but got %v", err)
}
snapshot, err = c.GetCompanyByMCMX("")
if snapshot == nil {
t.Error("snapshot returned nil")
}
if err != nil {
t.Errorf("error expected nil but got %v", err)
}
results, err := c.SearchCompaniesByName("")
if results == nil {
t.Error("results returned nil")
}
if len(results) == 0 {
t.Error("results length = 0")
}
if err != nil {
t.Errorf("error expected nil but got %v", err)
}
}
func BenchmarkClient_GetCompanyByDOTNumber(b *testing.B) {
node, _ := htmlquery.LoadDoc("./testdata/snapshot-basic.html")
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
_, _ = htmlNodeToCompanySnapshot(node)
}
}
func BenchmarkClient_Search_4Results(b *testing.B) {
node, _ := htmlquery.LoadDoc("./testdata/search-result-short.html")
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
_, _ = htmlNodeToCompanyResults(node)
}
}
func BenchmarkClient_Search_484Results(b *testing.B) {
node, _ := htmlquery.LoadDoc("./testdata/search-result.html")
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
_, _ = htmlNodeToCompanyResults(node)
}
}