-
Notifications
You must be signed in to change notification settings - Fork 0
/
open_graph_test.go
82 lines (76 loc) · 1.88 KB
/
open_graph_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
package main
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRoutes(t *testing.T) {
testCases := map[string]struct {
path string
ua string
goldenFile string
}{
"job slug fb": {
path: "/job/blockchain-developer-44",
ua: "facebookexternalhit",
goldenFile: "goldenFiles/job_slug_fb.html",
},
"job slug -fb": {
path: "/job/blockchain-developer-44",
ua: "",
goldenFile: "goldenFiles/job_slug_-fb.html",
},
"job -slug fb": {
path: "/job/x",
ua: "facebookexternalhit",
goldenFile: "goldenFiles/job_-slug_fb.html",
},
"job -slug -fb": {
path: "/job/x",
ua: "",
goldenFile: "goldenFiles/job_-slug_-fb.html",
},
"profile slug fb": {
path: "/profile/johan-deecke-292",
ua: "facebookexternalhit",
goldenFile: "goldenFiles/profile_slug_fb.html",
},
"profile slug -fb": {
path: "/profile/johan-deecke-292",
ua: "",
goldenFile: "goldenFiles/profile_slug_-fb.html",
},
"profile -slug fb": {
path: "/profile/x",
ua: "facebookexternalhit",
goldenFile: "goldenFiles/profile_-slug_fb.html",
},
"profile -slug -fb": {
path: "/profile/x",
ua: "",
goldenFile: "goldenFiles/profile_-slug_-fb.html",
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
router := setupRouter()
w := httptest.NewRecorder()
w.Header().Set("User-Agent", tc.ua)
w.WriteHeader(200)
req, _ := http.NewRequest("GET", tc.path, nil)
router.ServeHTTP(w, req)
got := w.Body.String()
f, err := os.Open(tc.goldenFile)
if err != nil {
t.Fatalf("os.Open() err = %s; want nil", err)
}
want, err := ioutil.ReadAll(f)
f.Close()
assert.Equal(t, 200, w.Code)
assert.Equal(t, want, got)
})
}
}