support cors in rest server

This commit is contained in:
kevin
2020-10-21 14:10:29 +08:00
parent 1c1e4bca86
commit fe0d0687f5
8 changed files with 122 additions and 8 deletions

View File

@@ -12,6 +12,11 @@ import (
"github.com/tal-tech/go-zero/rest/router"
)
func TestNewServer(t *testing.T) {
_, err := NewServer(RestConf{}, WithNotFoundHandler(nil), WithNotAllowedHandler(nil))
assert.NotNil(t, err)
}
func TestWithMiddleware(t *testing.T) {
m := make(map[string]string)
router := router.NewRouter()
@@ -69,7 +74,7 @@ func TestWithMiddleware(t *testing.T) {
}, m)
}
func TestMultiMiddleware(t *testing.T) {
func TestMultiMiddlewares(t *testing.T) {
m := make(map[string]string)
router := router.NewRouter()
handler := func(w http.ResponseWriter, r *http.Request) {
@@ -140,3 +145,9 @@ func TestMultiMiddleware(t *testing.T) {
"whatever": "200000200000",
}, m)
}
func TestWithPriority(t *testing.T) {
var fr featuredRoutes
WithPriority()(&fr)
assert.True(t, fr.priority)
}