mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-24 01:30:25 +08:00
fc04ad7854
* refactor * export pathvar for user-defined routers
33 lines
648 B
Go
33 lines
648 B
Go
package pathvar
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestVars(t *testing.T) {
|
|
expect := map[string]string{
|
|
"a": "1",
|
|
"b": "2",
|
|
}
|
|
r, err := http.NewRequest(http.MethodGet, "/", nil)
|
|
assert.Nil(t, err)
|
|
r = r.WithContext(context.WithValue(context.Background(), pathVars, expect))
|
|
assert.EqualValues(t, expect, Vars(r))
|
|
}
|
|
|
|
func TestVarsNil(t *testing.T) {
|
|
r, err := http.NewRequest(http.MethodGet, "/", nil)
|
|
assert.Nil(t, err)
|
|
assert.Nil(t, Vars(r))
|
|
}
|
|
|
|
func TestContextKey(t *testing.T) {
|
|
ck := contextKey("hello")
|
|
assert.True(t, strings.Contains(ck.String(), "hello"))
|
|
}
|