Skip to content

Commit 472ed2f

Browse files
committed
feat : add code coverage
1 parent ce6bfa0 commit 472ed2f

File tree

5 files changed

+121
-92
lines changed

5 files changed

+121
-92
lines changed

.github/workflows/dockerimage.yml

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,51 @@
11
name: gobot ci
22

3-
on:
4-
[push]
3+
on: [push]
54

65
jobs:
7-
86
build:
97
runs-on: ubuntu-latest
8+
109
steps:
11-
- uses: actions/checkout@v2
12-
- name: Set up Go
13-
uses: actions/setup-go@v2
14-
with:
15-
go-version: 1.17
16-
17-
- name: Build gobot
18-
run: go build -o bot_linux
19-
20-
- name: Login
21-
uses: docker/login-action@v1
22-
with:
23-
username: ${{ secrets.DOCKERHUB_NAME }}
24-
password: ${{ secrets.DOCKERHUB_TOKEN }}
25-
26-
- name: Build and push
27-
id: docker_build
28-
uses: docker/build-push-action@v2
29-
with:
30-
context: .
31-
file: ./Dockerfile
32-
push: true
33-
tags: braidgo/gobot-driver:v${{ github.run_id }}.${{ github.run_number }}
10+
- uses: actions/checkout@v2
11+
- name: Set up Go
12+
uses: actions/setup-go@v2
13+
with:
14+
go-version: 1.17
15+
16+
- name: Build gobot
17+
run: go build -o bot_linux
18+
19+
- name: Login
20+
uses: docker/login-action@v1
21+
with:
22+
username: ${{ secrets.DOCKERHUB_NAME }}
23+
password: ${{ secrets.DOCKERHUB_TOKEN }}
24+
25+
- name: Build and push
26+
id: docker_build
27+
uses: docker/build-push-action@v2
28+
with:
29+
context: .
30+
file: ./Dockerfile
31+
push: true
32+
tags: braidgo/gobot-driver:v${{ github.run_id }}.${{ github.run_number }}
33+
34+
# Runs a single command using the runners shell
35+
- name: unit test
36+
run: |
37+
cd $SRCDIR
38+
go test -race -covermode atomic -coverprofile=covprofile ./...
39+
40+
- name: Install goveralls
41+
env:
42+
GO111MODULE: off
43+
run: |
44+
go get github.com/mattn/goveralls
45+
46+
- name: Send coverage
47+
env:
48+
COVERALLS_TOKEN: ${{secrets.GITHUB_TOKEN}}
49+
run: |
50+
cd $SRCDIR
51+
goveralls -coverprofile=covprofile -service=github

README.md

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# gobot
22
Gobot is a stateful api testing tool that supports graph editing, api calling, and binding script execution.
33

4+
[![Go Report Card](https://goreportcard.com/badge/github.com/pojol/gobot)](https://goreportcard.com/report/github.com/pojol/gobot)
45
[![](https://img.shields.io/badge/%E6%96%87%E6%A1%A3-Doc-2ca5e0?style=flat&logo=github)](https://pojol.gitee.io/gobot/#/)
56
[![](https://img.shields.io/badge/Trello-Todo-2ca5e0?style=flat&logo=trello)](https://trello.com/b/8eDZ6h7n/)
67
[![CI](https://github.com/pojol/gobot/actions/workflows/dockerimage.yml/badge.svg?branch=develop)](https://github.com/pojol/gobot/actions/workflows/dockerimage.yml)
@@ -21,45 +22,20 @@ Gobot is a stateful api testing tool that supports graph editing, api calling, a
2122
* Provides a report viewing page (api statistics called by the robot
2223
* Provide `prefab` template code function in config
2324

25+
### Script Module
26+
|||||||
27+
|-|-|-|-|-|-|
28+
|`base64`|`http`|`protobuf`|`mongoDB`|`json`|
29+
|`md5`|`uuid`|`random`|...|
30+
2431
# Try it out
2532
Try the editor out [on website](http://123.60.17.61:7777)
2633

27-
2834
### Preview
2935
[![botgif2.gif](https://i.postimg.cc/SNKQG50m/botgif2.gif)](https://www.bilibili.com/video/BV1sS4y1z7Dg?share_source=copy_web)
3036

31-
### Http request sample
32-
```lua
33-
-- lua script
34-
local http = require("http")
35-
36-
reqTable = {
37-
body = {}, -- post body
38-
timeout = "10s", -- http timeout
39-
headers = {}, -- http headers
40-
}
4137

42-
-- .post .put .get
43-
res, err = http.post("url", reqTable)
4438

45-
--[[
46-
res -- userdata
47-
res["body"] -- http response body
48-
res["body_size"] -- body size
49-
res["headers"] -- http headers
50-
res["cookies"] -- http cookies
51-
res["status_code"] -- http status code
52-
res["url"] -- request url
53-
54-
err -- error message
55-
]]--
56-
```
57-
58-
### Script Module
59-
|||||||
60-
|-|-|-|-|-|-|
61-
|`base64`|`http`|`protobuf`|`mongoDB`|`json`|
62-
|`md5`|`uuid`|`random`|...|
6339

6440
### Report
6541
[![image.png](https://i.postimg.cc/4d3TTrvf/image.png)](https://postimg.cc/yJ2Gmprt)

README_CN.md

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# gobot editor
22
Gobot是一个有状态的api测试工具,支持图形编辑、api调用、绑定脚本执行。
33

4+
[![Go Report Card](https://goreportcard.com/badge/github.com/pojol/gobot)](https://goreportcard.com/report/github.com/pojol/gobot)
45
[![](https://img.shields.io/badge/%E6%96%87%E6%A1%A3-Doc-2ca5e0?style=flat&logo=github)](https://pojol.gitee.io/gobot/#/)
56
[![](https://img.shields.io/badge/Trello-Todo-2ca5e0?style=flat&logo=trello)](https://trello.com/b/8eDZ6h7n/)
67
[![CI](https://github.com/pojol/gobot/actions/workflows/dockerimage.yml/badge.svg?branch=develop)](https://github.com/pojol/gobot/actions/workflows/dockerimage.yml)
@@ -11,7 +12,7 @@ Gobot是一个有状态的api测试工具,支持图形编辑、api调用、绑
1112
> 当前市面上绝大部分的测试工具都是基于单条API进行测试的,但是我们同样也有一些API会依赖各种状态,例如社交中想要测试一些行为必须先是好友关系,例如游戏中想要进入战斗必须要有编队信息等等,gobot 拥有完整的生命周期我们可以在不同的节点(测试)上,保留和使用各种状态信息。
1213
1314
* **降低使用门槛**
14-
> 在定制AI逻辑的时候,首先我们想到的是使用代码(或者脚本)进行控制,这会让使用的门槛相对有些高;在 gobot 中我们可以使用界面化的工具`行为树编辑器`对机器人进行流程上的编辑,避免了手写相关控制代码
15+
> 在定制AI逻辑的时候,首先我们想到的是使用代码(或者脚本)进行控制,这会让使用的门槛相对有些高;在 gobot 中我们可以使用界面化的工具`行为树编辑器`对机器人进行流程上的编辑,避免了手写相关控制代码
1516
1617
* **提供API接口**
1718
> 由于现代的服务器体系中引入了大量的 CI/CD 流程,在使用 gobot 的时候,我们也可以方便的在流程中插入API调用`post /bot.run -d '{"Name":"某个机器人"}'`来进行集成测试。
@@ -26,6 +27,11 @@ Gobot是一个有状态的api测试工具,支持图形编辑、api调用、绑
2627
6. 提供报告查看页(机器人调用的api统计信息
2728
7. 在配置页中可以进行模版代码`预制`,为自己添加功能节点或模版节点
2829

30+
### 脚本层模块
31+
|||||||
32+
|-|-|-|-|-|-|
33+
|`base64`|`http`|`protobuf`|`mongoDB`|`json`|
34+
|`md5`|`uuid`|`random`|...|
2935

3036
### [在线试用](http://123.60.17.61:7777) <--
3137
### [文档](https://pojol.gitee.io/gobot/#/) <--
@@ -34,37 +40,7 @@ Gobot是一个有状态的api测试工具,支持图形编辑、api调用、绑
3440
### 编辑器预览
3541
[![botgif2.gif](https://i.postimg.cc/SNKQG50m/botgif2.gif)](https://www.bilibili.com/video/BV1sS4y1z7Dg?share_source=copy_web)
3642

37-
### 一个http节点的例子
38-
```lua
39-
-- lua script
40-
local http = require("http")
41-
42-
reqTable = {
43-
body = {}, -- 消息内容
44-
timeout = "10s", -- http 请求超时时间
45-
headers = {}, -- http 消息头
46-
}
47-
48-
-- .post .put .get
49-
res, err = http.post("url", reqTable)
5043

51-
--[[
52-
res -- userdata
53-
res["body"] -- http 回复内容
54-
res["body_size"] -- 回复内容大小
55-
res["headers"] -- http 消息头
56-
res["cookies"] -- http cookies
57-
res["status_code"] -- http 状态码
58-
res["url"] -- 请求地址
59-
60-
err -- 错误信息
61-
]]--
62-
```
63-
64-
### 脚本层支持的模块
65-
|||||||
66-
|-|-|-|-|-|-|
67-
|`base64`|`http`|`protobuf`|`utils`|`mongoDB`|`json`|
6844

6945
### Report
7046
[![image.png](https://i.postimg.cc/4d3TTrvf/image.png)](https://www.bilibili.com/video/BV1sS4y1z7Dg?share_source=copy_web)

coverage.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
# Generate test coverage statistics for Go packages.
3+
#
4+
# Works around the fact that `go test -coverprofile` currently does not work
5+
# with multiple packages, see https://code.google.com/p/go/issues/detail?id=6909
6+
#
7+
# Usage: coverage.sh [--html|--coveralls]
8+
#
9+
# --html Additionally create HTML report
10+
# --coveralls Push coverage statistics to coveralls.io
11+
#
12+
13+
set -e
14+
15+
workdir=.cover
16+
profile="$workdir/cover.out"
17+
mode=count
18+
19+
generate_cover_data() {
20+
rm -rf "$workdir"
21+
mkdir "$workdir"
22+
23+
for pkg in "$@"; do
24+
f="$workdir/$(echo $pkg | tr / -).cover"
25+
go test -covermode="$mode" -coverprofile="$f" "$pkg"
26+
done
27+
28+
echo "mode: $mode" >"$profile"
29+
grep -h -v "^mode:" "$workdir"/*.cover >>"$profile"
30+
}
31+
32+
show_html_report() {
33+
go tool cover -html="$profile" -o="$workdir"/coverage.html
34+
}
35+
36+
show_csv_report() {
37+
go tool cover -func="$profile" -o="$workdir"/coverage.csv
38+
}
39+
40+
push_to_coveralls() {
41+
echo "Pushing coverage statistics to coveralls.io"
42+
echo $GOPATH
43+
# ignore failure to push - it happens
44+
goveralls -coverprofile="$profile" \
45+
-service=github || true
46+
}
47+
48+
generate_cover_data $(go list ./... | grep -v /vendor/)
49+
show_csv_report
50+
51+
case "$1" in
52+
"")
53+
;;
54+
--html)
55+
show_html_report ;;
56+
--coveralls)
57+
push_to_coveralls ;;
58+
*)
59+
echo >&2 "error: invalid option: $1"; exit 1 ;;
60+
esac

main.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ import (
1919
var (
2020
help bool
2121

22-
dbmode bool
23-
reportLimit int
24-
batchSize int
25-
scriptPath string
22+
dbmode bool
23+
batchSize int
24+
scriptPath string
2625
)
2726

2827
const (

0 commit comments

Comments
 (0)