-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmain_test.go
More file actions
104 lines (76 loc) · 1.76 KB
/
Copy pathmain_test.go
File metadata and controls
104 lines (76 loc) · 1.76 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
var (
server *httptest.Server
)
func init() {
SetupGlobals()
server = httptest.NewServer(CreateRouter())
}
func search(t testing.TB, path string) string {
resp, err := http.Get(server.URL + path)
if err != nil {
t.Fatal(err)
}
if resp.StatusCode != 200 {
t.Fatalf("Received non-200 response: %d\n", resp.StatusCode)
}
body, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
t.Fatal(err)
}
return string(body)
}
func TestHomepageLooksOkay(t *testing.T) {
t.Parallel()
body := search(t, "")
if !strings.Contains(body, "Common Search") {
t.Fatal("Should contain Common Search!")
}
if strings.Contains(body, "xxxteststring") {
t.Fatal("Should not contain xxxteststring!")
}
}
func TestLocalizedHomepageLooksOkay(t *testing.T) {
t.Parallel()
body := search(t, "/?g=fr")
if !strings.Contains(body, ""fr"") {
t.Fatal("Should be set as french!")
}
}
func TestTestSearchLooksOkay(t *testing.T) {
t.Parallel()
body := search(t, "/?q=xxxteststring")
if !strings.Contains(body, "xxxteststring") {
t.Fatal("Should contain xxxteststring!")
}
if !strings.Contains(body, "http://www.example.com/page/1") {
t.Fatal("Should contain example!")
}
}
func TestStaticFiles(t *testing.T) {
t.Parallel()
body := search(t, "/js/index.js")
if !strings.Contains(body, ".XMLHttpRequest") {
t.Fatal("Should be JavaScript!")
}
favicon := search(t, "/favicon.ico")
if len(favicon) < 500 || len(favicon) > 50000 {
t.Fatal("Strange favicon!")
}
}
func BenchmarkHomepage(b *testing.B) {
for n := 0; n < b.N; n++ {
body := search(b, "")
if !strings.Contains(body, "Common Search") {
b.Fatal("Should contain Common Search!")
}
}
}