127 lines
2.6 KiB
Go
Raw Normal View History

2017-06-22 14:08:34 +00:00
package main
import (
2017-10-15 23:07:08 +00:00
"fmt"
2017-06-22 14:08:34 +00:00
"net/http"
"net/http/httptest"
2019-06-02 03:30:25 +00:00
"strings"
2017-06-22 14:08:34 +00:00
"testing"
"github.com/aerogo/aero"
2019-06-03 09:32:43 +00:00
"github.com/animenotifier/notify.moe/arn"
2018-03-27 23:32:49 +00:00
"github.com/animenotifier/notify.moe/utils/routetests"
2018-11-08 17:34:04 +00:00
"github.com/stretchr/testify/assert"
2017-06-22 14:08:34 +00:00
)
2018-04-25 21:45:11 +00:00
func TestRoutes(t *testing.T) {
t.Parallel()
2017-06-22 14:08:34 +00:00
app := configure(aero.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 {
2018-04-25 21:45:11 +00:00
testRoute(t, app, example)
2017-10-01 22:31:44 +00:00
}
}
}
2018-04-25 21:45:11 +00:00
func TestAnimePages(t *testing.T) {
t.Parallel()
app := configure(aero.New())
2019-06-01 15:28:22 +00:00
app.BindMiddleware()
2018-04-25 21:45:11 +00:00
for anime := range arn.StreamAnime() {
testRoute(t, app, anime.Link())
}
}
func TestSoundTrackPages(t *testing.T) {
t.Parallel()
app := configure(aero.New())
2019-06-01 15:28:22 +00:00
app.BindMiddleware()
2018-04-25 21:45:11 +00:00
for soundtrack := range arn.StreamSoundTracks() {
testRoute(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 TestAMVPages(t *testing.T) {
t.Parallel()
app := configure(aero.New())
2019-06-01 15:28:22 +00:00
app.BindMiddleware()
2018-04-25 21:45:11 +00:00
for amv := range arn.StreamAMVs() {
testRoute(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 TestCompanyPages(t *testing.T) {
t.Parallel()
app := configure(aero.New())
2019-06-01 15:28:22 +00:00
app.BindMiddleware()
2018-04-25 21:45:11 +00:00
for company := range arn.StreamCompanies() {
testRoute(t, app, company.Link())
}
}
func TestThreadPages(t *testing.T) {
t.Parallel()
app := configure(aero.New())
2019-06-01 15:28:22 +00:00
app.BindMiddleware()
2018-04-25 21:45:11 +00:00
for thread := range arn.StreamThreads() {
testRoute(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 TestPostPages(t *testing.T) {
t.Parallel()
app := configure(aero.New())
2019-06-01 15:28:22 +00:00
app.BindMiddleware()
2018-04-25 21:45:11 +00:00
for post := range arn.StreamPosts() {
testRoute(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 TestQuotePages(t *testing.T) {
t.Parallel()
app := configure(aero.New())
2019-06-01 15:28:22 +00:00
app.BindMiddleware()
2018-04-25 21:45:11 +00:00
for quote := range arn.StreamQuotes() {
testRoute(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
}
}
2019-04-28 16:00:57 +00:00
// func TestUserPages(t *testing.T) {
// t.Parallel()
// app := configure(aero.New())
// for user := range arn.StreamUsers() {
// testRoute(t, app, user.Link())
// }
// }
2018-04-25 22:06:13 +00:00
2018-04-25 21:45:11 +00:00
func testRoute(t *testing.T, app *aero.Application, 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 {
case 200, 302:
// 200 and 302 are allowed
default:
panic(fmt.Errorf("%s | Wrong status code | %v instead of %v", route, status, http.StatusOK))
}
}