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"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/aerogo/aero"
|
2018-04-25 21:45:11 +00:00
|
|
|
"github.com/animenotifier/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())
|
|
|
|
|
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())
|
|
|
|
|
|
|
|
for anime := range arn.StreamAnime() {
|
|
|
|
testRoute(t, app, anime.Link())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSoundTrackPages(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
app := configure(aero.New())
|
|
|
|
|
|
|
|
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())
|
|
|
|
|
|
|
|
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())
|
|
|
|
|
|
|
|
for company := range arn.StreamCompanies() {
|
|
|
|
testRoute(t, app, company.Link())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestThreadPages(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
app := configure(aero.New())
|
|
|
|
|
|
|
|
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())
|
|
|
|
|
|
|
|
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())
|
|
|
|
|
|
|
|
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) {
|
|
|
|
// Create a new HTTP request
|
|
|
|
request, err := http.NewRequest("GET", route, nil)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Record the response
|
|
|
|
responseRecorder := httptest.NewRecorder()
|
|
|
|
app.Handler().ServeHTTP(responseRecorder, request)
|
|
|
|
status := responseRecorder.Code
|
|
|
|
|
|
|
|
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))
|
|
|
|
}
|
|
|
|
}
|