Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
glennliao committed Mar 4, 2023
1 parent 3442aa9 commit 5d1ab9f
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 8 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
.idea
*.exe
config.yaml
test
*.exe
2 changes: 1 addition & 1 deletion @doc/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

1. 这东西有什么用?
2. 我的接口业务流程很复杂怎么处理?
3. 你知道graphql吗?
3. 知道graphql吗?
4. 如何完成文件上传下载、微信支付等操作?
5. 我项目中没有使用goframe, 会有gin、beego等框架的版本吗?
24 changes: 20 additions & 4 deletions drivers/framework_goframe/gf.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ func New(a *apijson.ApiJson) *GF {
}
}

func (gf *GF) Run(s ...*ghttp.Server) {

var server *ghttp.Server

if len(s) == 0 {
server = g.Server("apijson")
} else {
server = s[0]
}

server.Group("/", func(group *ghttp.RouterGroup) {
gf.Bind(group)
})
server.Run()
}

func (gf *GF) Bind(group *ghttp.RouterGroup, mode ...Mode) {
if len(mode) == 0 {
mode = []Mode{InDataMode}
Expand All @@ -38,11 +54,11 @@ func (gf *GF) Bind(group *ghttp.RouterGroup, mode ...Mode) {
group.POST("/delete", gf.commonResponse(gf.Delete, mode[0]))
}

func (g *GF) Get(ctx context.Context, req model.Map) (res model.Map, err error) {
func (gf *GF) Get(ctx context.Context, req model.Map) (res model.Map, err error) {
q := query.New(ctx, req)
q.NoAccessVerify = g.apijson.Config().Access.NoVerify
q.Access = g.apijson.Config().Access
q.AccessCondition = g.apijson.Config().Access.ConditionFunc
q.NoAccessVerify = gf.apijson.Config().Access.NoVerify
q.Access = gf.apijson.Config().Access
q.AccessCondition = gf.apijson.Config().Access.ConditionFunc
return q.Result()
}

Expand Down
15 changes: 15 additions & 0 deletions test/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[server]
address = ":8091"
dumpRouterMap = false
debug = false

[logger]
level = "info"

[database.logger]
level = "all"
stdout = true

[database.default]
debug = true
link = "sqlite::@file(./db.sqlite3)"
7 changes: 7 additions & 0 deletions test/test.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### list
POST http://localhost:8091/get
Content-Type: application/json

{
"t_todo": {}
}
16 changes: 16 additions & 0 deletions test/z_app_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import (
"context"
"github.com/glennliao/apijson-go"
)

type User struct {
}

type Todo struct {
}

func App(ctx context.Context, a *apijson.ApiJson) {

}
72 changes: 72 additions & 0 deletions test/z_main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package main

import (
"github.com/glennliao/apijson-go"
_ "github.com/glennliao/apijson-go/drivers/executor/goframe" // need import for executor with goframe
"github.com/glennliao/apijson-go/drivers/framework_goframe"
"github.com/glennliao/apijson-go/model"
"github.com/glennliao/apijson-go/query"
_ "github.com/gogf/gf/contrib/drivers/sqlite/v2" // need import for sqlite
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
"testing"
)

var a *apijson.ApiJson

func init() {
a = apijson.Load(App)
}

// notice: import section
func TestServer(t *testing.T) {
s := framework_goframe.New(a)
s.Run()
// then test in test.http
}

func TestQuery(t *testing.T) {

ctx := gctx.New()
q := query.New(ctx, model.Map{
"t_user": model.Map{
"id": "123",
"id{}": []string{"123", "456"},
"id>": "222",
"@column": "id,userId",
},
"t_user[]": model.Map{
//"userId": "123",
},
//"t_todo": model.Map{},
//"_access": model.Map{},
})

q.NoAccessVerify = true //config.AccessVerify
q.Access = a.Config().Access

result, err := q.Result()

if err != nil {
panic(err)
}

g.Dump(result)

}

func BenchmarkName(b *testing.B) {
for i := 0; i < b.N; i++ {
ctx := gctx.New()

q := query.New(ctx, model.Map{
"Todo": model.Map{},
"User": model.Map{},
})

_, err := q.Result()
if err != nil {
panic(err)
}
}
}

0 comments on commit 5d1ab9f

Please sign in to comment.