forked from gobuffalo/buffalo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
route_info_test.go
51 lines (38 loc) · 1.06 KB
/
route_info_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package buffalo
import (
"database/sql"
"fmt"
"net/http"
"testing"
"github.com/gobuffalo/buffalo/render"
"github.com/gobuffalo/httptest"
"github.com/stretchr/testify/require"
)
func Test_RouteInfo_ServeHTTP_SQL_Error(t *testing.T) {
r := require.New(t)
app := New(Options{})
app.GET("/good", func(c Context) error {
return c.Render(http.StatusOK, render.String("hi"))
})
app.GET("/bad", func(c Context) error {
return sql.ErrNoRows
})
app.GET("/bad-2", func(c Context) error {
return sql.ErrTxDone
})
app.GET("/gone-unwrap", func(c Context) error {
return c.Error(http.StatusGone, sql.ErrTxDone)
})
app.GET("/gone-wrap", func(c Context) error {
return c.Error(http.StatusGone, fmt.Errorf("some error wrapping here: %w", sql.ErrNoRows))
})
w := httptest.New(app)
res := w.HTML("/good").Get()
r.Equal(http.StatusOK, res.Code)
res = w.HTML("/bad").Get()
r.Equal(http.StatusNotFound, res.Code)
res = w.HTML("/gone-wrap").Get()
r.Equal(http.StatusGone, res.Code)
res = w.HTML("/gone-unwrap").Get()
r.Equal(http.StatusGone, res.Code)
}