Skip to content

Commit

Permalink
feat : add code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
pojol committed Jul 20, 2022
1 parent ce6bfa0 commit 472ed2f
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 92 deletions.
70 changes: 44 additions & 26 deletions .github/workflows/dockerimage.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,51 @@
name: gobot ci

on:
[push]
on: [push]

jobs:

build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17

- name: Build gobot
run: go build -o bot_linux

- name: Login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_NAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: braidgo/gobot-driver:v${{ github.run_id }}.${{ github.run_number }}
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17

- name: Build gobot
run: go build -o bot_linux

- name: Login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_NAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: braidgo/gobot-driver:v${{ github.run_id }}.${{ github.run_number }}

# Runs a single command using the runners shell
- name: unit test
run: |
cd $SRCDIR
go test -race -covermode atomic -coverprofile=covprofile ./...
- name: Install goveralls
env:
GO111MODULE: off
run: |
go get github.com/mattn/goveralls
- name: Send coverage
env:
COVERALLS_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: |
cd $SRCDIR
goveralls -coverprofile=covprofile -service=github
38 changes: 7 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# gobot
Gobot is a stateful api testing tool that supports graph editing, api calling, and binding script execution.

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

### Script Module
|||||||
|-|-|-|-|-|-|
|`base64`|`http`|`protobuf`|`mongoDB`|`json`|
|`md5`|`uuid`|`random`|...|

# Try it out
Try the editor out [on website](http://123.60.17.61:7777)


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

### Http request sample
```lua
-- lua script
local http = require("http")

reqTable = {
body = {}, -- post body
timeout = "10s", -- http timeout
headers = {}, -- http headers
}

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

--[[
res -- userdata
res["body"] -- http response body
res["body_size"] -- body size
res["headers"] -- http headers
res["cookies"] -- http cookies
res["status_code"] -- http status code
res["url"] -- request url
err -- error message
]]--
```

### Script Module
|||||||
|-|-|-|-|-|-|
|`base64`|`http`|`protobuf`|`mongoDB`|`json`|
|`md5`|`uuid`|`random`|...|

### Report
[![image.png](https://i.postimg.cc/4d3TTrvf/image.png)](https://postimg.cc/yJ2Gmprt)
38 changes: 7 additions & 31 deletions README_CN.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# gobot editor
Gobot是一个有状态的api测试工具,支持图形编辑、api调用、绑定脚本执行。

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

### 脚本层模块
|||||||
|-|-|-|-|-|-|
|`base64`|`http`|`protobuf`|`mongoDB`|`json`|
|`md5`|`uuid`|`random`|...|

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

### 一个http节点的例子
```lua
-- lua script
local http = require("http")

reqTable = {
body = {}, -- 消息内容
timeout = "10s", -- http 请求超时时间
headers = {}, -- http 消息头
}

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

--[[
res -- userdata
res["body"] -- http 回复内容
res["body_size"] -- 回复内容大小
res["headers"] -- http 消息头
res["cookies"] -- http cookies
res["status_code"] -- http 状态码
res["url"] -- 请求地址
err -- 错误信息
]]--
```

### 脚本层支持的模块
|||||||
|-|-|-|-|-|-|
|`base64`|`http`|`protobuf`|`utils`|`mongoDB`|`json`|

### Report
[![image.png](https://i.postimg.cc/4d3TTrvf/image.png)](https://www.bilibili.com/video/BV1sS4y1z7Dg?share_source=copy_web)
60 changes: 60 additions & 0 deletions coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash
# Generate test coverage statistics for Go packages.
#
# Works around the fact that `go test -coverprofile` currently does not work
# with multiple packages, see https://code.google.com/p/go/issues/detail?id=6909
#
# Usage: coverage.sh [--html|--coveralls]
#
# --html Additionally create HTML report
# --coveralls Push coverage statistics to coveralls.io
#

set -e

workdir=.cover
profile="$workdir/cover.out"
mode=count

generate_cover_data() {
rm -rf "$workdir"
mkdir "$workdir"

for pkg in "$@"; do
f="$workdir/$(echo $pkg | tr / -).cover"
go test -covermode="$mode" -coverprofile="$f" "$pkg"
done

echo "mode: $mode" >"$profile"
grep -h -v "^mode:" "$workdir"/*.cover >>"$profile"
}

show_html_report() {
go tool cover -html="$profile" -o="$workdir"/coverage.html
}

show_csv_report() {
go tool cover -func="$profile" -o="$workdir"/coverage.csv
}

push_to_coveralls() {
echo "Pushing coverage statistics to coveralls.io"
echo $GOPATH
# ignore failure to push - it happens
goveralls -coverprofile="$profile" \
-service=github || true
}

generate_cover_data $(go list ./... | grep -v /vendor/)
show_csv_report

case "$1" in
"")
;;
--html)
show_html_report ;;
--coveralls)
push_to_coveralls ;;
*)
echo >&2 "error: invalid option: $1"; exit 1 ;;
esac
7 changes: 3 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import (
var (
help bool

dbmode bool
reportLimit int
batchSize int
scriptPath string
dbmode bool
batchSize int
scriptPath string
)

const (
Expand Down

0 comments on commit 472ed2f

Please sign in to comment.