From ba84bd54887dadd0743037883128bb7a714e5989 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 22 Jun 2017 16:08:34 +0200 Subject: [PATCH] Added basic test --- main.go | 8 ++++++-- main_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 main_test.go diff --git a/main.go b/main.go index ce0a57af..60dd7a12 100644 --- a/main.go +++ b/main.go @@ -32,6 +32,11 @@ import ( var app = aero.New() func main() { + // Configure and start + configure(app).Run() +} + +func configure(app *aero.Application) *aero.Application { // HTTPS app.Security.Load("security/fullchain.pem", "security/privkey.pem") @@ -84,6 +89,5 @@ func main() { // Authentication auth.Install(app) - // Let's go - app.Run() + return app } diff --git a/main_test.go b/main_test.go new file mode 100644 index 00000000..e35031c9 --- /dev/null +++ b/main_test.go @@ -0,0 +1,27 @@ +package main + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/aerogo/aero" +) + +func TestRoutes(t *testing.T) { + expectedStatus := http.StatusOK + + app := configure(aero.New()) + request, err := http.NewRequest("GET", "/", nil) + + if err != nil { + t.Fatal(err) + } + + responseRecorder := httptest.NewRecorder() + app.Handler().ServeHTTP(responseRecorder, request) + + if status := responseRecorder.Code; status != expectedStatus { + t.Errorf("Wrong status code: %v instead of %v", status, expectedStatus) + } +}