-
Notifications
You must be signed in to change notification settings - Fork 2
/
flags_test.go
33 lines (29 loc) · 659 Bytes
/
flags_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
package accessflags
import (
"github.com/go-martini/martini"
"net/http"
"net/http/httptest"
"testing"
)
const (
rolePassing = 0
roleRobot = 1
roleSignOn = 2
roleAdmin = 4 | roleSignOn
)
func TestFlags(t *testing.T) {
m := martini.Classic()
m.Use(func(r *http.Request, c martini.Context) {
// something
c.Map(roleRobot) // forbidden access profile
})
m.Get("/profile", Forbidden(roleSignOn), func() string {
return "hello"
})
w := httptest.NewRecorder()
r, _ := http.NewRequest("GET", "/profile", nil)
m.ServeHTTP(w, r)
if w.Code != http.StatusForbidden {
t.Fatal("Expected Forbidden, but got:", http.StatusText(w.Code))
}
}