github.com/Mrs4s/go-cqhttp@v1.2.0/server/http_test.go (about) 1 package server 2 3 import ( 4 "net/url" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 "github.com/tidwall/gjson" 9 ) 10 11 func TestHttpCtx_Get(t *testing.T) { 12 cases := []struct { 13 ctx *httpCtx 14 key string 15 expected string 16 }{ 17 { 18 ctx: &httpCtx{ 19 json: gjson.Result{}, 20 query: url.Values{ 21 "sub_type": []string{"hello"}, 22 "type": []string{"world"}, 23 }, 24 }, 25 key: "[sub_type,type].0", 26 expected: "hello", 27 }, 28 { 29 ctx: &httpCtx{ 30 json: gjson.Result{}, 31 query: url.Values{ 32 "type": []string{"114514"}, 33 }, 34 }, 35 key: "[sub_type,type].0", 36 expected: "114514", 37 }, 38 } 39 for _, c := range cases { 40 assert.Equal(t, c.expected, c.ctx.Get(c.key).String()) 41 } 42 }