-
Notifications
You must be signed in to change notification settings - Fork 4
/
is_test.go
77 lines (63 loc) · 1.37 KB
/
is_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
package is
import (
"context"
"net/http"
"net/url"
"os"
"strings"
"testing"
"time"
"github.com/wabarc/helper"
)
var handler = func(w http.ResponseWriter, r *http.Request) {
page := "testdata/homepage.html"
switch {
case strings.Contains(r.URL.Path, "submit"):
// wayback or save
case r.Method == http.MethodGet && r.URL.Path != "/":
// playback or search
page = "testdata/search.html"
}
buf, err := os.ReadFile(page)
if err != nil {
_, _ = w.Write([]byte(``))
} else {
_, _ = w.Write(buf)
}
}
func TestWayback(t *testing.T) {
httpClient, mux, server := helper.MockServer()
defer server.Close()
mux.HandleFunc("/", handler)
uri := "https://example.com"
u, err := url.Parse(uri)
if err != nil {
t.Fatal(err)
}
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
arc := NewArchiver(httpClient)
defer arc.CloseTor()
_, err = arc.Wayback(ctx, u)
if err != nil {
t.Fatal(err)
}
}
func TestPlayback(t *testing.T) {
httpClient, mux, server := helper.MockServer()
defer server.Close()
mux.HandleFunc("/", handler)
uri := "https://example.com"
u, err := url.Parse(uri)
if err != nil {
t.Fatal(err)
}
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
arc := NewArchiver(httpClient)
defer arc.CloseTor()
_, err = arc.Playback(ctx, u)
if err != nil {
t.Fatal(err)
}
}