37 lines
905 B
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"
"testing"
"github.com/aerogo/aero"
)
2018-03-21 19:22:57 +00:00
// TestRouteStatusCodes tests the status code of every route registered in routeTests.
func TestRouteStatusCodes(t *testing.T) {
2017-06-22 14:08:34 +00:00
app := configure(aero.New())
2018-03-21 19:22:57 +00:00
// Iterate through every route
2017-07-02 15:51:17 +00:00
for _, examples := range routeTests {
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-03-21 19:22:57 +00:00
// Create a new HTTP request
2017-06-25 10:05:32 +00:00
request, err := http.NewRequest("GET", example, nil)
if err != nil {
t.Fatal(err)
}
2017-06-22 14:08:34 +00:00
2018-03-21 19:22:57 +00:00
// Record the response without actually starting the server
2017-06-25 10:05:32 +00:00
responseRecorder := httptest.NewRecorder()
app.Handler().ServeHTTP(responseRecorder, request)
2017-06-22 14:08:34 +00:00
2017-06-25 10:05:32 +00:00
if status := responseRecorder.Code; status != http.StatusOK {
2017-10-15 23:07:08 +00:00
panic(fmt.Errorf("%s | Wrong status code | %v instead of %v", example, status, http.StatusOK))
2017-10-01 22:31:44 +00:00
}
}
}
}