1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-05 03:23:49 +08:00
go-cqhttp/server/http_test.go
2022-01-30 14:28:22 +08:00

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())
}
}