118 lines
2.4 KiB
Go
Raw Normal View History

2017-06-22 14:08:34 +00:00
package main
import (
"net/http"
"net/http/httptest"
2019-06-02 03:30:25 +00:00
"strings"
2017-06-22 14:08:34 +00:00
"testing"
2019-08-25 06:15:32 +00:00
"github.com/akyoto/assert"
2019-06-03 09:32:43 +00:00
"github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/notify.moe/server"
2018-03-27 23:32:49 +00:00
"github.com/animenotifier/notify.moe/utils/routetests"
2017-06-22 14:08:34 +00:00
)
2018-04-25 21:45:11 +00:00
func TestRoutes(t *testing.T) {
app := server.New()
2019-06-01 15:28:22 +00:00
app.BindMiddleware()
2017-06-22 14:08:34 +00:00
2018-03-21 19:22:57 +00:00
// Iterate through every route
2018-03-27 23:32:49 +00:00
for _, examples := range routetests.All() {
2018-03-21 19:22:57 +00:00
// Iterate through every example specified for that route
2017-06-25 10:05:32 +00:00
for _, example := range examples {
fetch(t, app, example)
2017-10-01 22:31:44 +00:00
}
}
}
2018-04-25 21:45:11 +00:00
func TestAnime(t *testing.T) {
app := server.New()
2019-06-01 15:28:22 +00:00
app.BindMiddleware()
2018-04-25 21:45:11 +00:00
for anime := range arn.StreamAnime() {
fetch(t, app, anime.Link())
2018-04-25 21:45:11 +00:00
}
}
func TestSoundTracks(t *testing.T) {
app := server.New()
2019-06-01 15:28:22 +00:00
app.BindMiddleware()
2018-04-25 21:45:11 +00:00
for soundtrack := range arn.StreamSoundTracks() {
fetch(t, app, soundtrack.Link())
2018-11-08 17:34:04 +00:00
assert.NotNil(t, soundtrack.Creator())
2018-04-25 21:45:11 +00:00
}
}
func TestAMVs(t *testing.T) {
app := server.New()
2019-06-01 15:28:22 +00:00
app.BindMiddleware()
2018-04-25 21:45:11 +00:00
for amv := range arn.StreamAMVs() {
fetch(t, app, amv.Link())
2018-11-08 17:34:04 +00:00
assert.NotNil(t, amv.Creator())
2018-04-25 21:45:11 +00:00
}
}
func TestCompanies(t *testing.T) {
app := server.New()
2019-06-01 15:28:22 +00:00
app.BindMiddleware()
2018-04-25 21:45:11 +00:00
for company := range arn.StreamCompanies() {
fetch(t, app, company.Link())
2018-04-25 21:45:11 +00:00
}
}
func TestThreads(t *testing.T) {
app := server.New()
2019-06-01 15:28:22 +00:00
app.BindMiddleware()
2018-04-25 21:45:11 +00:00
for thread := range arn.StreamThreads() {
fetch(t, app, thread.Link())
2018-11-08 17:34:04 +00:00
assert.NotNil(t, thread.Creator())
2018-04-25 21:45:11 +00:00
}
}
func TestPosts(t *testing.T) {
app := server.New()
2019-06-01 15:28:22 +00:00
app.BindMiddleware()
2018-04-25 21:45:11 +00:00
for post := range arn.StreamPosts() {
fetch(t, app, post.Link())
2018-11-08 17:34:04 +00:00
assert.NotNil(t, post.Creator())
2018-04-25 21:45:11 +00:00
}
}
func TestQuotes(t *testing.T) {
app := server.New()
2019-06-01 15:28:22 +00:00
app.BindMiddleware()
2018-04-25 21:45:11 +00:00
for quote := range arn.StreamQuotes() {
fetch(t, app, quote.Link())
2018-11-08 17:34:04 +00:00
assert.NotNil(t, quote.Creator())
2018-04-25 21:45:11 +00:00
}
}
func TestUsers(t *testing.T) {
app := server.New()
app.BindMiddleware()
2019-04-28 16:00:57 +00:00
for user := range arn.StreamUsers() {
fetch(t, app, user.Link())
}
}
2018-04-25 22:06:13 +00:00
func fetch(t *testing.T, app http.Handler, route string) {
2019-06-02 03:30:25 +00:00
request := httptest.NewRequest("GET", strings.ReplaceAll(route, " ", "%20"), nil)
2019-06-01 15:28:22 +00:00
response := httptest.NewRecorder()
app.ServeHTTP(response, request)
status := response.Code
2018-04-25 21:45:11 +00:00
switch status {
2019-06-03 09:36:59 +00:00
case http.StatusOK, http.StatusTemporaryRedirect, http.StatusPermanentRedirect:
// OK
2018-04-25 21:45:11 +00:00
default:
2019-06-05 07:18:04 +00:00
t.Fatalf("%s | Wrong status code | %v instead of %v", route, status, http.StatusOK)
2018-04-25 21:45:11 +00:00
}
}