mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-03 00:38:40 +08:00
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
|
package gateway
|
||
|
|
||
|
import (
|
||
|
"net/http/httptest"
|
||
|
"strings"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
"github.com/zeromicro/go-zero/rest/pathvar"
|
||
|
)
|
||
|
|
||
|
func TestNewRequestParserNoVar(t *testing.T) {
|
||
|
req := httptest.NewRequest("GET", "/", nil)
|
||
|
parser, err := newRequestParser(req, nil)
|
||
|
assert.Nil(t, err)
|
||
|
assert.NotNil(t, parser)
|
||
|
}
|
||
|
|
||
|
func TestNewRequestParserWithVars(t *testing.T) {
|
||
|
req := httptest.NewRequest("GET", "/", nil)
|
||
|
req = pathvar.WithVars(req, map[string]string{"a": "b"})
|
||
|
parser, err := newRequestParser(req, nil)
|
||
|
assert.Nil(t, err)
|
||
|
assert.NotNil(t, parser)
|
||
|
}
|
||
|
|
||
|
func TestNewRequestParserNoVarWithBody(t *testing.T) {
|
||
|
req := httptest.NewRequest("GET", "/", strings.NewReader(`{"a": "b"}`))
|
||
|
parser, err := newRequestParser(req, nil)
|
||
|
assert.Nil(t, err)
|
||
|
assert.NotNil(t, parser)
|
||
|
}
|
||
|
|
||
|
func TestNewRequestParserWithVarsWithBody(t *testing.T) {
|
||
|
req := httptest.NewRequest("GET", "/", strings.NewReader(`{"a": "b"}`))
|
||
|
req = pathvar.WithVars(req, map[string]string{"c": "d"})
|
||
|
parser, err := newRequestParser(req, nil)
|
||
|
assert.Nil(t, err)
|
||
|
assert.NotNil(t, parser)
|
||
|
}
|
||
|
|
||
|
func TestNewRequestParserWithVarsWithWrongBody(t *testing.T) {
|
||
|
req := httptest.NewRequest("GET", "/", strings.NewReader(`{"a": "b"`))
|
||
|
req = pathvar.WithVars(req, map[string]string{"c": "d"})
|
||
|
parser, err := newRequestParser(req, nil)
|
||
|
assert.NotNil(t, err)
|
||
|
assert.Nil(t, parser)
|
||
|
}
|