Skip to content

Commit

Permalink
helpers: Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xplodwild committed Mar 22, 2020
1 parent ac544c6 commit 11dc724
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions helpers_test.go
@@ -0,0 +1,34 @@
package ace

import (
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"testing"
)

func TestHandleServeFileFallback(t *testing.T) {
ass := assert.New(t)

a := Default()
a.RouteNotFound(HandleServeFileFallback("./", "./README.md"))

r, _ := http.NewRequest("GET", "/notExisting", nil)
w := httptest.NewRecorder()
a.ServeHTTP(w, r)
ass.Equal(StatusOK, w.Code)
ass.Equal("ACE", w.Body.String()[:3])

r, _ = http.NewRequest("GET", "/LICENSE", nil)
w = httptest.NewRecorder()
a.ServeHTTP(w, r)
ass.Equal(StatusOK, w.Code)
ass.Equal("Apache", w.Body.String()[:6])

// Ensure we get 500 when the fallback file doesn't exist
a.RouteNotFound(HandleServeFileFallback("./", "./notExistingFile"))
r, _ = http.NewRequest("GET", "/notExisting", nil)
w = httptest.NewRecorder()
a.ServeHTTP(w, r)
ass.Equal(StatusInternalServerError, w.Code)
}

0 comments on commit 11dc724

Please sign in to comment.