-
Notifications
You must be signed in to change notification settings - Fork 652
/
Copy pathapi_test.go
32 lines (29 loc) · 930 Bytes
/
api_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package share
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/yaoapp/gou/session"
)
func TestGetQueryParam(t *testing.T) {
SessionServerStart()
defer SessionServerStop()
sid := session.ID()
s := session.Global().ID(sid).Expire(5000 * time.Microsecond)
s.MustSet("id", 10086)
s.MustSet("extra", map[string]interface{}{"gender": "男"})
query := map[string]interface{}{
"select": []string{"id", "name"},
"wheres": []map[string]interface{}{
{"column": "id", "op": "=", "value": "{{id}}"},
{"column": "gender", "op": "=", "value": "{{extra.gender}}"},
},
}
param := GetQueryParam(query, sid)
assert.Equal(t, "id", param.Wheres[0].Column)
assert.Equal(t, "=", param.Wheres[0].OP)
assert.Equal(t, float64(10086), param.Wheres[0].Value)
assert.Equal(t, "gender", param.Wheres[1].Column)
assert.Equal(t, "=", param.Wheres[1].OP)
assert.Equal(t, "男", param.Wheres[1].Value)
}