-
Notifications
You must be signed in to change notification settings - Fork 2
/
onion_scraper_test.go
66 lines (53 loc) · 1.14 KB
/
onion_scraper_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
package main
import (
"os"
"strings"
"testing"
)
func TestClient(t *testing.T) {
client, err := NewClient("", 0)
if err != nil {
t.Error(err)
return
}
// official tor onion link
resp, err := client.Request(Address("expyuzz4wqqyqhjn"))
if err != nil {
t.Error(err)
return
}
t.Logf("Title: %s\nDescription: %s\n", resp.Title, resp.Description)
resp, err = client.Request(Address("bla"))
if err == nil {
t.Error("We should get error, insted we go response:", *resp)
}
}
func TestStore(t *testing.T) {
_, err := NewStore().CSV("")
if err == nil {
t.Error("Filename empty but we got a file!")
return
}
_, err = NewStore().CSV("testing.csv")
if err != nil {
t.Error(err)
return
}
// file should be created
// now remove it
os.Remove("testing.csv")
}
func TestGenerator(t *testing.T) {
checkOnionURL(t, RandOnionV2())
checkOnionURL(t, RandOnionV3())
}
func checkOnionURL(t *testing.T, addr Address) {
if strings.Contains(string(addr), "http://") {
t.Error("It should not contain http", addr)
return
}
if !strings.Contains(addr.Addr(), "http://") {
t.Error("Format onion url wrong", addr.Addr())
return
}
}