-
Notifications
You must be signed in to change notification settings - Fork 1
/
capture_test.go
63 lines (52 loc) · 1.24 KB
/
capture_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
// +build integration
package archiveis
import (
"fmt"
"math/rand"
"testing"
"time"
)
const (
page = "https://github.com/jaytaylor/archive.is"
maxSleep = 60
)
func TestCapture1(t *testing.T) {
randSleep(t, maxSleep)
// Link which has been submitted before.
url, err := Capture(page)
if err != nil {
t.Fatal(err)
}
t.Logf("Resolved URL=%q", url)
}
func TestCapture2(t *testing.T) {
randSleep(t, maxSleep)
// Link which has likely not been submitted before.
url, err := Capture(fmt.Sprintf("%v?%v", page, time.Now().Unix()))
if err != nil {
t.Fatal(err)
}
t.Logf("Resolved URL=%q", url)
}
func TestCapture3(t *testing.T) {
randSleep(t, maxSleep)
cfg := Config{
Wait: true,
WaitTimeout: 180 * time.Second,
PollInterval: 15 * time.Second,
RequestTimeout: 15 * time.Second,
}
// Link which has likely not been submitted before.
url, err := Capture(fmt.Sprintf("%v?%v", page, time.Now().Unix()), cfg)
if err != nil {
t.Fatal(err)
}
t.Logf("Resolved URL=%q", url)
}
// randSleep helps smooth out travis running so many builds at once.
func randSleep(t *testing.T, max int) {
n := rand.Int() % max
d := time.Duration(n) * time.Second
t.Logf("Sleeping for randomly selected interval: %s", d)
time.Sleep(d)
}