A Comprehensive Coverage Testing System for The Go Programming Language

goc

Go Report Card Build Release codecov GoDoc

中文页 |

goc is a comprehensive coverage testing system for The Go Programming Language, especially for some complex scenarios, like system testing code coverage collection and accurate testing.

Enjoy, Have Fun! Demo

Installation

Download the latest version from Github Releases page.

Goc supports both GOPATH project and Go Modules project with Go 1.11+. However, for developing goc, you need to install Go 1.13+.

Examples

You can use goc tool in many scenarios.

Code Coverage Collection for Your Golang System Tests

Goc can collect code coverages at runtime for your long-run golang applications. To do that, normally just need three steps:

  1. use goc server to start a service registry center:
    ➜  simple-go-server git:(master) ✗ goc server
    
  2. use goc build to build the target service, and run the generated binary. Here let's take the simple-go-server project as example:
    ➜  simple-go-server git:(master) ✗ goc build .
    ... // omit logs
    ➜  simple-go-server git:(master) ✗ ./simple-go-server  
    
  3. use goc profile to get the code coverage profile of the started simple server above:
    ➜  simple-go-server git:(master) ✗ goc profile
    mode: atomic
    enricofoltran/simple-go-server/main.go:30.13,48.33 13 1
    enricofoltran/simple-go-server/main.go:48.33,50.3 1 0
    enricofoltran/simple-go-server/main.go:52.2,65.12 5 1
    enricofoltran/simple-go-server/main.go:65.12,74.46 7 1
    enricofoltran/simple-go-server/main.go:74.46,76.4 1 0
    ...   
    

Show Code Coverage Change at Runtime in Vscode

We provide a vscode extension - Goc Coverage which can show highlighted covered source code at runtime.

Extension

Tips

  1. To understand the execution details of goc tool, you can use the --debug flag. Also we appreciate if you can provide such logs when submitting a bug to us.

  2. By default, the covered service will listen a random port in order to communicate with the goc server. This may not be suitable in docker or kubernetes environment since the port must be exposed explicitly in order to be accessible by others in such environment. For this kind of scenario, you can use --agentport flag to specify a fixed port when calling goc build or goc install.

  3. To use a remote goc server, you can use --center flag to compile the target service with goc build or goc install command.

  4. The coverage data is stored on each covered service side, so if one service needs to restart during test, this service's coverage data will be lost. For this case, you can use following steps to handle:

    1. Before the service restarts, collect coverage with goc profile -o a.cov
    2. After service restarted and test finished, collect coverage again with goc profile -o b.cov
    3. Merge two coverage profiles together: goc merge a.cov b.cov -o merge.cov

RoadMap

  • Support code coverage collection for system testing.
  • Support code coverage counters clear for the services under test at runtime.
  • Support develop mode towards accurate testing.
  • Support code coverage diff based on Pull Request.
  • Optimize the performance costed by code coverage counters.

Contributing

We welcome all kinds of contribution, including bug reports, feature requests, documentation improvements, UI refinements, etc.

Thanks to all contributors!!

License

Goc is released under the Apache 2.0 license. See LICENSE.txt

Join goc WeChat Group

WeChat

Owner
Qiniu Cloud
Connect Data, Redefine Value.
Qiniu Cloud
Comments
  • fix:fix server address error when running in k8s

    fix:fix server address error when running in k8s

    when goc server running in k8s client register uri while be transform to is proxy address in fact,there is no need to transform

    add address uri check,make sure address parm is a complete uri

  • coverage block mismatch

    coverage block mismatch

    启动了两个服务,执行goc profile get收集时报如下错误:不匹配是什么原因?单个服务可正常收集

    Goc server http://127.0.0.1:7777 return an error: {"error":"error merging main/main.go: coverage block mismatch: block #0 for main/main.go ({StartLine:12 StartCol:13 EndLine:16 EndCol:34 NumStmt:2 Count:1} mismatches {StartLine:9 StartCol:13 EndLine:14 EndCol:34 NumStmt:2 Count:1})"}

  • 支持设定service name

    支持设定service name

    build时候支持设置service_name,不只是使用可执行文件作为name

    1. 补充说明一下这么做的原因,以便评估是否需要
    2. build 不是唯一会编译的命令,还有 install/run

    抱歉前段时间有点忙,现在才回复。

    1. 项目部署的服务的文件名都是一样的,需要指定一个服务名来区分不同的微服务进程
    2. 已经在run和intsall补上
  • goc build err but i can't understand , I need  your help

    goc build err but i can't understand , I need your help

    "github.com/sparrc/go-ping" I use goPing library in my projects . when i run the command "goc build ." error occurs but i can't understand.

    mistake ./http_cover_apis_auto_generated.go:2135:89: undefined: cache_343664633233633838353763.GoCacheCover_0_34636232323162626631 ./http_cover_apis_auto_generated.go:2137:88: undefined: cache_343664633233633838353763.GoCacheCover_1_34636232323162626631 ./http_cover_apis_auto_generated.go:3978:17: undefined: cache_343664633233633838353763.GoCacheCover_0_34636232323162626631 ./http_cover_apis_auto_generated.go:3980:17: undefined: cache_343664633233633838353763.GoCacheCover_1_34636232323162626631 FATA Fail to build: fail to execute: [/bin/bash -c go build -o /home/test .], err: exit status 2

  • cannot build if go.mod has relative path 'replace' directive

    cannot build if go.mod has relative path 'replace' directive

    项目比较大,各种依赖很复杂,有十几个文件,之前都是用makefile编译的 执行goc build .报错 go: $path/[email protected]: parsing $path/go.mod: open $path/go.mod: no such file or directory FATA Fail to build: fail to execute: [/bin/bash -c go build -o $path/$program .], err: exit status 1 试了下用go build .可以成功编译

  • Fix nil issue when failed to register with coverage center.

    Fix nil issue when failed to register with coverage center.

    When "register" POST request failed, the "resp" will be nil, so we should check the nil before close "resp.Body" in defer.

  • unable to build project [https://github.com/enricofoltran/simple-go-server]

    unable to build project [https://github.com/enricofoltran/simple-go-server]

    Steps:

    1. workspace and environment
    ➜  simple-go-server git:(master) echo $GOPATH
    /Users/jicarl/k8s
    ➜  simple-go-server git:(master) pwd
    /Users/jicarl/qbox/simple-go-server
    ➜  simple-go-server git:(master) git remote -v
    origin	[email protected]:enricofoltran/simple-go-server.git (fetch)
    origin	[email protected]:enricofoltran/simple-go-server.git (push)
    ➜  simple-go-server git:(master)
    
    1. try to use goc command to build this project, but got errors:
    ➜  simple-go-server git:(master) goc build .
    2020/05/24 15:15:29 cover.go:114: go list cmd is: [go list -json . ./...]
    2020/05/24 15:15:29 tmpfolder.go:65: Temp project generated in: /var/folders/_6/t59gxn4d0zz12vqlm3j3gwhr0000gn/T/goc-055cb24d8755
    2020/05/24 15:15:29 tmpfolder.go:78: New working/building directory in: /var/folders/_6/t59gxn4d0zz12vqlm3j3gwhr0000gn/T/goc-055cb24d8755/Users/jicarl/qbox/simple-go-server
    2020/05/24 15:15:29 tmpfolder.go:47: New GOPATH: /var/folders/_6/t59gxn4d0zz12vqlm3j3gwhr0000gn/T/goc-055cb24d8755:/Users/jicarl/k8s
    2020/05/24 15:15:29 cover.go:114: go list cmd is: [go list -json . ./...]
    2020/05/24 15:15:29 build.go:61: Go building in temp...
    2020/05/24 15:15:29 build.go:74: Fail to execute: go build .. The error is: chdir /var/folders/_6/t59gxn4d0zz12vqlm3j3gwhr0000gn/T/goc-055cb24d8755/Users/jicarl/qbox/simple-go-server: no such file or directory, the stdout/stderr is:
    
  • Bump axios from 0.19.2 to 0.21.1 in /tools/vscode-ext

    Bump axios from 0.19.2 to 0.21.1 in /tools/vscode-ext

    Bumps axios from 0.19.2 to 0.21.1.

    Release notes

    Sourced from axios's releases.

    v0.21.1

    0.21.1 (December 21, 2020)

    Fixes and Functionality:

    • Hotfix: Prevent SSRF (#3410)
    • Protocol not parsed when setting proxy config from env vars (#3070)
    • Updating axios in types to be lower case (#2797)
    • Adding a type guard for AxiosError (#2949)

    Internal and Tests:

    • Remove the skipping of the socket http test (#3364)
    • Use different socket for Win32 test (#3375)

    Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:

    v0.21.0

    0.21.0 (October 23, 2020)

    Fixes and Functionality:

    • Fixing requestHeaders.Authorization (#3287)
    • Fixing node types (#3237)
    • Fixing axios.delete ignores config.data (#3282)
    • Revert "Fixing overwrite Blob/File type as Content-Type in browser. (#1773)" (#3289)
    • Fixing an issue that type 'null' and 'undefined' is not assignable to validateStatus when typescript strict option is enabled (#3200)

    Internal and Tests:

    • Lock travis to not use node v15 (#3361)

    Documentation:

    • Fixing simple typo, existant -> existent (#3252)
    • Fixing typos (#3309)

    Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:

    ... (truncated)

    Changelog

    Sourced from axios's changelog.

    0.21.1 (December 21, 2020)

    Fixes and Functionality:

    • Hotfix: Prevent SSRF (#3410)
    • Protocol not parsed when setting proxy config from env vars (#3070)
    • Updating axios in types to be lower case (#2797)
    • Adding a type guard for AxiosError (#2949)

    Internal and Tests:

    • Remove the skipping of the socket http test (#3364)
    • Use different socket for Win32 test (#3375)

    Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:

    0.21.0 (October 23, 2020)

    Fixes and Functionality:

    • Fixing requestHeaders.Authorization (#3287)
    • Fixing node types (#3237)
    • Fixing axios.delete ignores config.data (#3282)
    • Revert "Fixing overwrite Blob/File type as Content-Type in browser. (#1773)" (#3289)
    • Fixing an issue that type 'null' and 'undefined' is not assignable to validateStatus when typescript strict option is enabled (#3200)

    Internal and Tests:

    • Lock travis to not use node v15 (#3361)

    Documentation:

    • Fixing simple typo, existant -> existent (#3252)
    • Fixing typos (#3309)

    Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:

    ... (truncated)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

  • 增加一个获取远程仓库git info的命令

    增加一个获取远程仓库git info的命令

    背景: 1、容器中部署在远端,需要知道该容器中当前仓库的commitID以及branch信息(其实是需要版本信息) 2、同时有多个容器,且版本发布频繁,需要将覆盖率数据按照版本归类

    基于以上背景,想到goc server主动上报git相关信息,故产生该PR

    添加功能是仿照goc server 中removeServices功能实现

    请审批

  • File copy strategy of `goc build` needs to be optimized

    File copy strategy of `goc build` needs to be optimized

    Some files like unix socket is not allowed to be copied. When project files contians these file, goc build . will return an error. The file copy strategy needs optimize.

  • 服务监听固定端口--agentport参数貌似没有生效?

    服务监听固定端口--agentport参数貌似没有生效?

    各位贡献者,你们好! 这是一个超棒的工具! 我在使用的过程中,发现我设定固定监听端口没有生效,我是这样的一个过程: 1、首先启动server image 2、执行命令goc build --agentport :8080 --debug . image 3、goc run . image 发现端口还是随机生成的54776,并不是刚才注册的8080端口。

    是不是我漏掉了某些步骤? 然后我有用goc init重置配置,具体步骤如下: 1、执行goc init image 2、执行goc register -a "http://127.0.0.1:8080" -n simple-go-server --debug image 3、然后再执行 goc build --agentport :8080 --debug . && goc run . image 发现端口还是随机生成的! 最后用8080端口请求数据,发现报错,且返回为空: image 请大家指导~~~🌹

  • feat: support windows , run in multiple networks and support heartbeat

    feat: support windows , run in multiple networks and support heartbeat

    Hi, there. I made some features, hope can help you.

    1. Support compile projects on windows by goc.
    2. Fix goc client can not get the correct client-ip when the client has multiple networks, such as run in docker.
    3. The goc-client support register self to goc-server every 10 second. And the goc-sever kick out clients which is timeout (no register over 20 seconds) every 5 second.
  • k8s集群收集覆盖率不稳定

    k8s集群收集覆盖率不稳定

    执行goc profile 收集覆盖率时 报错信息如下,偶尔可以成功,多数都是失败的 error upstream connect error or disconnect/reset before headers. reset reason: connection failure, transport failure reason: delayed connect error: 111

  • 无法采集到覆盖率信息

    无法采集到覆盖率信息

    你好是这样的,我们的goc server部署在物理机a上,不是按照docker方式启动,但是我们的服务是以docker方式启动的,这样是不是要在服务以docker的方式启动的时候要加上-p参数暴露给goc server能访问的端口,且goc build的时候需要携带 --agentport参数来指定端口

  • FATA Fail to build: fail to execute: [/bin/bash -c go build  -o /git/projectdemo/tool .], err: exit status 1

    FATA Fail to build: fail to execute: [/bin/bash -c go build -o /git/projectdemo/tool .], err: exit status 1

    step1 :goc server
    step2: goc build.

    then got error :FATA Fail to build

    [root@localhost projectdemo]# goc build . no Go files in /tmp/goc-build-52be089fc042 FATA Fail to build: fail to execute: [/bin/bash -c go build -o /git/projectdemo/tool .], err: exit status 1

Hsuan-Fuzz: REST API Fuzzing by Coverage Level Guided Blackbox Testing
Hsuan-Fuzz: REST API Fuzzing by Coverage Level Guided Blackbox Testing

Hsuan-Fuzz: REST API Fuzzing by Coverage Level Guided Blackbox Testing Architecture Usage package main import ( restAPI "github.com/iasthc/hsuan-

Nov 30, 2022
Fundamental-Go - A comprehensive and FREE Online Go Development tutorial going step-by-step into the world of Go
Fundamental-Go - A comprehensive and FREE Online Go Development tutorial going step-by-step into the world of Go

FREE Reverse Engineering Self-Study Course HERE Fundamental Go The book and code

Mar 18, 2022
The portal gates to coverage reports
The portal gates to coverage reports

Covergates - Portal Gates to Coverage Reports Purpose Covergates is to make the easiest way to setup a self-hosted coverage report service. It's an al

Dec 18, 2022
go-carpet - show test coverage in terminal for Go source files
go-carpet - show test coverage in terminal for Go source files

go-carpet - show test coverage for Go source files To view the test coverage in the terminal, just run go-carpet. It works outside of the GOPATH direc

Jan 8, 2023
Generate a test coverage badge like this one for your go projects.

coverage-badge-go ?? Generate a test coverage badge like this one for your go projects. Usage on: pull_request: branches: -

Dec 11, 2022
Test coverage in Go, the whole package

Test coverage in Go, the whole package

Jan 20, 2022
siusiu (suite-suite harmonics) a suite used to manage the suite, designed to free penetration testing engineers from learning and using various security tools, reducing the time and effort spent by penetration testing engineers on installing tools, remembering how to use tools.
siusiu (suite-suite harmonics) a suite used to manage the suite, designed to free penetration testing engineers from learning and using various security tools, reducing the time and effort spent by penetration testing engineers on installing tools, remembering how to use tools.

siusiu (suite-suite harmonics) a suite used to manage the suite, designed to free penetration testing engineers from learning and using various security tools, reducing the time and effort spent by penetration testing engineers on installing tools, remembering how to use tools.

Dec 12, 2022
A yaml data-driven testing format together with golang testing library

Specimen Yaml-based data-driven testing Specimen is a yaml data format for data-driven testing. This enforces separation between feature being tested

Nov 24, 2022
Trade Matching / Transaction System Load Testing Solution

Load Generation System for Trade Matching Systems Operation Users select one of the following options from thew Test Management Portal: Generate a new

Feb 25, 2022
Rich testing for the Go language

Instructions Install the package with: go get gopkg.in/check.v1 Import it with: import "gopkg.in/check.v1" and use check as the package name inside

Dec 9, 2022
Hamcrest matchers for the Go programming language

Note: This has not been maintained and/or updated since 2011. Perhaps consider corbym/gocrest, instead. Introduction Hamcrest is a fluent framework fo

Sep 27, 2022
GoMock is a mocking framework for the Go programming language.

gomock GoMock is a mocking framework for the Go programming language. It integrates well with Go's built-in testing package, but can be used in other

Dec 28, 2022
Powerful mock generation tool for Go programming language

Summary Minimock generates mocks out of Go interface declarations. The main features of minimock are: It generates statically typed mocks and helpers.

Dec 17, 2022
Package cdp provides type-safe bindings for the Chrome DevTools Protocol (CDP), written in the Go programming language.

cdp Package cdp provides type-safe bindings for the Chrome DevTools Protocol (CDP), written in the Go programming language. The bindings are generated

Jan 7, 2023
Fortio load testing library, command line tool, advanced echo server and web UI in go (golang). Allows to specify a set query-per-second load and record latency histograms and other useful stats.
Fortio load testing library, command line tool, advanced echo server and web UI in go (golang). Allows to specify a set query-per-second load and record latency histograms and other useful stats.

Fortio Fortio (Φορτίο) started as, and is, Istio's load testing tool and now graduated to be its own project. Fortio is also used by, among others, Me

Jan 2, 2023
:exclamation:Basic Assertion Library used along side native go testing, with building blocks for custom assertions

Package assert Package assert is a Basic Assertion library used along side native go testing Installation Use go get. go get github.com/go-playground/

Jan 6, 2023
Expressive end-to-end HTTP API testing made easy in Go

baloo Expressive and versatile end-to-end HTTP API testing made easy in Go (golang), built on top of gentleman HTTP client toolkit. Take a look to the

Dec 13, 2022
Simple Go snapshot testing
Simple Go snapshot testing

Incredibly simple Go snapshot testing: cupaloy takes a snapshot of your test output and compares it to a snapshot committed alongside your tests. If t

Jan 5, 2023
Clean database for testing, inspired by database_cleaner for Ruby

DbCleaner Clean database for testing, inspired by database_cleaner for Ruby. It uses flock syscall under the hood to make sure the test can runs in pa

Nov 17, 2022