This repository has been archived by the owner on May 21, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathmain_test.go
123 lines (100 loc) · 2.47 KB
/
main_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/akyoto/assert"
"github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/notify.moe/server"
"github.com/animenotifier/notify.moe/utils/routetests"
)
func TestRoutes(t *testing.T) {
app := server.New()
app.BindMiddleware()
// Iterate through every route
for _, examples := range routetests.All() {
// Iterate through every example specified for that route
for _, example := range examples {
fetch(t, app, example)
}
}
}
func TestAnime(t *testing.T) {
app := server.New()
app.BindMiddleware()
for anime := range arn.StreamAnime() {
if anime.IsDraft {
continue
}
assert.True(t, anime.Title.Canonical != "")
fetch(t, app, anime.Link())
}
}
func TestSoundTracks(t *testing.T) {
app := server.New()
app.BindMiddleware()
for soundtrack := range arn.StreamSoundTracks() {
assert.NotNil(t, soundtrack.Creator())
fetch(t, app, soundtrack.Link())
}
}
func TestAMVs(t *testing.T) {
app := server.New()
app.BindMiddleware()
for amv := range arn.StreamAMVs() {
assert.NotNil(t, amv.Creator())
fetch(t, app, amv.Link())
}
}
func TestCompanies(t *testing.T) {
app := server.New()
app.BindMiddleware()
for company := range arn.StreamCompanies() {
fetch(t, app, company.Link())
}
}
func TestThreads(t *testing.T) {
app := server.New()
app.BindMiddleware()
for thread := range arn.StreamThreads() {
assert.NotNil(t, thread.Creator())
fetch(t, app, thread.Link())
}
}
func TestPosts(t *testing.T) {
app := server.New()
app.BindMiddleware()
for post := range arn.StreamPosts() {
assert.NotNil(t, post.Creator())
fetch(t, app, post.Link())
}
}
func TestQuotes(t *testing.T) {
app := server.New()
app.BindMiddleware()
for quote := range arn.StreamQuotes() {
assert.NotNil(t, quote.Creator())
fetch(t, app, quote.Link())
}
}
func TestUsers(t *testing.T) {
app := server.New()
app.BindMiddleware()
for user := range arn.StreamUsers() {
assert.True(t, user.Nick != "")
// fetch(t, app, user.Link())
}
}
func fetch(t *testing.T, app http.Handler, route string) {
request := httptest.NewRequest("GET", strings.ReplaceAll(route, " ", "%20"), nil)
response := httptest.NewRecorder()
app.ServeHTTP(response, request)
status := response.Code
switch status {
case http.StatusOK, http.StatusTemporaryRedirect, http.StatusPermanentRedirect:
// OK
default:
t.Fatalf("%s | Wrong status code | %v instead of %v", route, status, http.StatusOK)
}
}