Skip to content

Commit 5d1ab9f

Browse files
committed
add test
1 parent 3442aa9 commit 5d1ab9f

File tree

7 files changed

+132
-8
lines changed

7 files changed

+132
-8
lines changed

.gitignore

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
.idea
2-
*.exe
3-
config.yaml
4-
test
2+
*.exe

@doc/faq.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
1. 这东西有什么用?
44
2. 我的接口业务流程很复杂怎么处理?
5-
3. 你知道graphql吗?
5+
3. 知道graphql吗?
66
4. 如何完成文件上传下载、微信支付等操作?
77
5. 我项目中没有使用goframe, 会有gin、beego等框架的版本吗?

drivers/framework_goframe/gf.go

+20-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ func New(a *apijson.ApiJson) *GF {
2727
}
2828
}
2929

30+
func (gf *GF) Run(s ...*ghttp.Server) {
31+
32+
var server *ghttp.Server
33+
34+
if len(s) == 0 {
35+
server = g.Server("apijson")
36+
} else {
37+
server = s[0]
38+
}
39+
40+
server.Group("/", func(group *ghttp.RouterGroup) {
41+
gf.Bind(group)
42+
})
43+
server.Run()
44+
}
45+
3046
func (gf *GF) Bind(group *ghttp.RouterGroup, mode ...Mode) {
3147
if len(mode) == 0 {
3248
mode = []Mode{InDataMode}
@@ -38,11 +54,11 @@ func (gf *GF) Bind(group *ghttp.RouterGroup, mode ...Mode) {
3854
group.POST("/delete", gf.commonResponse(gf.Delete, mode[0]))
3955
}
4056

41-
func (g *GF) Get(ctx context.Context, req model.Map) (res model.Map, err error) {
57+
func (gf *GF) Get(ctx context.Context, req model.Map) (res model.Map, err error) {
4258
q := query.New(ctx, req)
43-
q.NoAccessVerify = g.apijson.Config().Access.NoVerify
44-
q.Access = g.apijson.Config().Access
45-
q.AccessCondition = g.apijson.Config().Access.ConditionFunc
59+
q.NoAccessVerify = gf.apijson.Config().Access.NoVerify
60+
q.Access = gf.apijson.Config().Access
61+
q.AccessCondition = gf.apijson.Config().Access.ConditionFunc
4662
return q.Result()
4763
}
4864

test/config.toml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[server]
2+
address = ":8091"
3+
dumpRouterMap = false
4+
debug = false
5+
6+
[logger]
7+
level = "info"
8+
9+
[database.logger]
10+
level = "all"
11+
stdout = true
12+
13+
[database.default]
14+
debug = true
15+
link = "sqlite::@file(./db.sqlite3)"

test/test.http

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
### list
2+
POST http://localhost:8091/get
3+
Content-Type: application/json
4+
5+
{
6+
"t_todo": {}
7+
}

test/z_app_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"github.com/glennliao/apijson-go"
6+
)
7+
8+
type User struct {
9+
}
10+
11+
type Todo struct {
12+
}
13+
14+
func App(ctx context.Context, a *apijson.ApiJson) {
15+
16+
}

test/z_main_test.go

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package main
2+
3+
import (
4+
"github.com/glennliao/apijson-go"
5+
_ "github.com/glennliao/apijson-go/drivers/executor/goframe" // need import for executor with goframe
6+
"github.com/glennliao/apijson-go/drivers/framework_goframe"
7+
"github.com/glennliao/apijson-go/model"
8+
"github.com/glennliao/apijson-go/query"
9+
_ "github.com/gogf/gf/contrib/drivers/sqlite/v2" // need import for sqlite
10+
"github.com/gogf/gf/v2/frame/g"
11+
"github.com/gogf/gf/v2/os/gctx"
12+
"testing"
13+
)
14+
15+
var a *apijson.ApiJson
16+
17+
func init() {
18+
a = apijson.Load(App)
19+
}
20+
21+
// notice: import section
22+
func TestServer(t *testing.T) {
23+
s := framework_goframe.New(a)
24+
s.Run()
25+
// then test in test.http
26+
}
27+
28+
func TestQuery(t *testing.T) {
29+
30+
ctx := gctx.New()
31+
q := query.New(ctx, model.Map{
32+
"t_user": model.Map{
33+
"id": "123",
34+
"id{}": []string{"123", "456"},
35+
"id>": "222",
36+
"@column": "id,userId",
37+
},
38+
"t_user[]": model.Map{
39+
//"userId": "123",
40+
},
41+
//"t_todo": model.Map{},
42+
//"_access": model.Map{},
43+
})
44+
45+
q.NoAccessVerify = true //config.AccessVerify
46+
q.Access = a.Config().Access
47+
48+
result, err := q.Result()
49+
50+
if err != nil {
51+
panic(err)
52+
}
53+
54+
g.Dump(result)
55+
56+
}
57+
58+
func BenchmarkName(b *testing.B) {
59+
for i := 0; i < b.N; i++ {
60+
ctx := gctx.New()
61+
62+
q := query.New(ctx, model.Map{
63+
"Todo": model.Map{},
64+
"User": model.Map{},
65+
})
66+
67+
_, err := q.Result()
68+
if err != nil {
69+
panic(err)
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)