MOVED TO GITLAB

blanket

blanket is a tool that helps you catch functions which don't have direct unit tests in your Go packages.

Installation

go get -u gitlab.com/verygoodsoftwarenotvirus/blanket

Docker Image

If you don't want to install blanket locally, you can use the pre-built Docker image like so:

docker run -it --rm -v "$(pwd):/src/<pkg>" verygoodsoftwarenotvirus/blanket:latest analyze --package <pkg>

Where <pkg> could be something like gitlab.com/verygoodsoftwarenotvirus/blanket/analysis. :)

Purpose

Say, for example, you had the following Go file:

package simple

func A() string {
    return "A"
}

func B() string {
    return "B"
}

func C() string {
    return "C"
}

func wrapper() {
   A()
   B()
   C()
}

and you had the following test for that file:

package simple

import (
    "testing"
)

func TestA(t *testing.T) {
    A()
}

func TestC(t *testing.T) {
    C()
}

func TestWrapper(t *testing.T) {
    wrapper()
}

Running go test -cover on that package yields the following output:

PASS
coverage: 100.0% of statements
ok      gitlab.com/verygoodsoftwarenotvirus/blanket/example_packages/simple    0.006s

However, note that B doesn't have a direct test the way that A and C do. B is only "tested" in TestWrapper. Because all the functions are called, -cover yields a 100% coverage value. If you ever decide that wrapper doesn't need to call B anymore, and don't delete the function entirely, you'll have a drop in coverage. Running blanket analyze on that same package yields the following output:

Functions without direct unit tests:
in /Users/vgsnv/golang/src/gitlab.com/verygoodsoftwarenotvirus/blanket/example_packages/simple/main.go:
    B on line 7

Grade: 75% (3/4 functions)

Additionally, you can use the cover command to visualize those functions by passing in a cover profile. So if you run something like go test -coverprofile=coverage.out && blanket cover --html=coverage.out, a browser window will open that shows untested functions in red, functions without direct tests in yellow, and functions that are directly tested in green, like so:

example output

Use Cases

What blanket seeks to do is catch these sorts of things so that package maintainers can decide what the appropriate course of action is. If you're fine with it, that's cool. If you're not cool with it, then you know what needs to have tests added.

You can also use blanket in your CI pipeline to decline PRs that would add functions that don't have direct unit tests. As a matter of fact, blanket does just that for itself! Here is an example of such a scenario working on this very repository!

I think blanket could also be helpful for new developers looking to contribute towards a project. They can run blanket on the package and see if there are some functions they could easily add unit tests for, just to get their feet wet in a project.

Issues

If you've tried blanket on something and found that it didn't accurately handle some code, or panicked, please feel free to file an issue. Having an example of the code you experienced issues with is pretty crucial, so keep that in mind.

Known Issues

blanket doesn't adequately handle deeply nested method calls. So if you had something like this:

package main

import (
    "testing"
)

/*
// in another file:
type Example struct{}
func methodCall() {
    return
}
*/

func TestMethod(t *testing.T) {
    x := struct{
        First: struct{
            Second: struct{
                Third: Example{},
            },
        },
    }
    x.First.Second.Third.methodCall()
}

That should technically satisfy blanket's strict testing requirement, but it doesn't. Blanket can handle single-level selector expressions with great ease, but it doesn't recursively dive into those selectors for a number of reasons.

Comments
  • Add HTML coverage support

    Add HTML coverage support

    This support is still being tested, but there have been enough additions to the code to warrant merging it in with the rest of the project. None of those additions have any impact on the existing commands' functions.

  • Reduce instances where panics can happen.

    Reduce instances where panics can happen.

    This change attempts to guarantee that you won't run into panics when runningblanket analyze on your codebase.

    It doesn't guarantee that it will accurately catch all of your function and method calls, but it does attempt to guarantee that nothing will panic.

  • Convert to structure

    Convert to structure

    The existing layout of blanket meant that it was pretty inflexible. These changes should make testing blanket more productive, and also allow others to integrate blanket into their tools via the client library.

  • added hashbang, set -e, and removeFunc to coverage.sh

    added hashbang, set -e, and removeFunc to coverage.sh

    Added a few little things to this shell script to beef it up a bit.

    • env based #!
    • set -e so the script exists on any error, instead of continuing as the (odd) default of shell scripts
    • created a function for removeCoverageOut to DRY things up a bit.
  • Add demonstration function

    Add demonstration function

    This commit should fail the Travis build, because while I added demonstration(), and it is covered by the test for analyze(), I don't have a direct test for it.

A tool to cleanup stale gitlab runners

clinar - A tool to cleanup stale gitlab runners This tool basically get’s all offline runners which a user can administer. If you don’t provide the --

Dec 14, 2022
list or create gitlab project level variables for gitops

intro gitlab ci requires some env variables, for diffent projects these env vars may be same. so we have this cmd tool -- gitlab-vars install simplely

Dec 1, 2021
An open-source GitLab command line tool bringing GitLab's cool features to your command line
An open-source GitLab command line tool bringing GitLab's cool features to your command line

GLab is an open source GitLab CLI tool bringing GitLab to your terminal next to where you are already working with git and your code without switching

Dec 30, 2022
A GitLab API client enabling Go programs to interact with GitLab in a simple and uniform way

go-gitlab A GitLab API client enabling Go programs to interact with GitLab in a simple and uniform way NOTE Release v0.6.0 (released on 25-08-2017) no

Jan 6, 2023
A GitLab API client enabling Go programs to interact with GitLab in a simple and uniform way

A GitLab API client enabling Go programs to interact with GitLab in a simple and uniform way

Dec 28, 2022
Gitlab Command to simplify some Gitlab Workflow

GitLabCommand - glc - README How to use ? ensure glc.yaml is configured with the valid token and url gitlab_token: <your valid token> gitlab_url: ht

Oct 14, 2021
A GitLab API client enabling Go programs to interact with GitLab in a simple and uniform way

TEMPORARY REPOSITORY This repo will exist only temporarily waiting for the PR has been merged.

Nov 5, 2021
🤖 Prune old images on GitHub (ghcr.io) and GitLab (registry.gitlab.com) container registry
🤖 Prune old images on GitHub (ghcr.io) and GitLab (registry.gitlab.com) container registry

✨ Prune container images in a CLI way ✨ Prune old images on GitHub (ghcr.io) and GitLab (registry.gitlab.com) Container Registry Getting Started | Des

Dec 15, 2022
Simple and Powerful ORM for Go, support mysql,postgres,tidb,sqlite3,mssql,oracle, Moved to https://gitea.com/xorm/xorm

xorm HAS BEEN MOVED TO https://gitea.com/xorm/xorm . THIS REPOSITORY WILL NOT BE UPDATED ANY MORE. 中文 Xorm is a simple and powerful ORM for Go. Featur

Jan 3, 2023
This is only a mirror and Moved to https://gitea.com/lunny/tango

Tango 简体中文 Package tango is a micro & pluggable web framework for Go. Current version: v0.5.0 Version History Getting Started To install Tango: go get

Nov 18, 2022
:exclamation::exclamation::exclamation: [deprecated] Moved to https://github.com/go-macaron/macaron
:exclamation::exclamation::exclamation: [deprecated] Moved to https://github.com/go-macaron/macaron

Macaron Package macaron is a high productive and modular web framework in Go. Current version: 0.6.8 Getting Started The minimum requirement of Go is

Aug 20, 2021
Moved https://gitea.com/xweb/xweb

xweb xweb是一个强大的Go语言web框架。 English 技术支持 QQ群:369240307 更新日志 v0.2.1 : 自动Binding新增对jquery对象,map和array的支持。 v0.2 : 新增 validation 子包,从 https://github.com/ast

Apr 21, 2022
Moved to https://gitea.com/lunny/gop

GOP 简体中文 GOP is a project manangement tool for building your golang applications out of global GOPATH. In fact gop will keep both global GOPATH and ev

Nov 2, 2022
DEPRECATED (moved to tendermint/tendermint): Golang P2P library

tendermint/go-p2p tendermint/go-p2p provides an abstraction around peer-to-peer communication. Peer/MConnection/Channel Each peer has one MConnection

Nov 9, 2022
:exclamation::exclamation::exclamation: [deprecated] Moved to https://github.com/go-macaron/macaron
:exclamation::exclamation::exclamation: [deprecated] Moved to https://github.com/go-macaron/macaron

Macaron Package macaron is a high productive and modular web framework in Go. Current version: 0.6.8 Getting Started The minimum requirement of Go is

Aug 20, 2021
This is only a mirror and Moved to https://gitea.com/lunny/tango

Tango 简体中文 Package tango is a micro & pluggable web framework for Go. Current version: v0.5.0 Version History Getting Started To install Tango: go get

Nov 18, 2022
Moved https://gitea.com/xweb/xweb

xweb xweb是一个强大的Go语言web框架。 English 技术支持 QQ群:369240307 更新日志 v0.2.1 : 自动Binding新增对jquery对象,map和array的支持。 v0.2 : 新增 validation 子包,从 https://github.com/ast

Apr 21, 2022
Quickly clone an entire org/users repositories into one directory - Supports GitHub, GitLab, Bitbucket, and more
Quickly clone an entire org/users repositories into one directory - Supports GitHub, GitLab, Bitbucket, and more

ghorg ghorg allows you to quickly clone all of an orgs, or users repos into a single directory. This can be useful in many situations including Search

Jan 1, 2023
:fishing_pole_and_fish: Webhook receiver for GitHub, Bitbucket, GitLab, Gogs

Library webhooks Library webhooks allows for easy receiving and parsing of GitHub, Bitbucket and GitLab Webhook Events Features: Parses the entire pay

Jan 4, 2023
Display last GitLab project git commit. Page is optimized for an e-paper device.
Display last GitLab project git commit. Page is optimized for an e-paper device.

git-on-epaper A gitlab webhook for push notifications on a project. The webhook serves a HTML that shows the last push on the project with the followi

Dec 12, 2022