mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-04 19:17:37 +08:00
43 lines
723 B
Go
43 lines
723 B
Go
package server
|
|
|
|
import (
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/tidwall/gjson"
|
|
)
|
|
|
|
func TestHttpCtx_Get(t *testing.T) {
|
|
cases := []struct {
|
|
ctx *httpCtx
|
|
key string
|
|
expected string
|
|
}{
|
|
{
|
|
ctx: &httpCtx{
|
|
json: gjson.Result{},
|
|
query: url.Values{
|
|
"sub_type": []string{"hello"},
|
|
"type": []string{"world"},
|
|
},
|
|
},
|
|
key: "[sub_type,type].0",
|
|
expected: "hello",
|
|
},
|
|
{
|
|
ctx: &httpCtx{
|
|
json: gjson.Result{},
|
|
query: url.Values{
|
|
"type": []string{"114514"},
|
|
},
|
|
},
|
|
key: "[sub_type,type].0",
|
|
expected: "114514",
|
|
},
|
|
}
|
|
for _, c := range cases {
|
|
assert.Equal(t, c.expected, c.ctx.Get(c.key).String())
|
|
}
|
|
}
|