failpoints for go
Branch: master
Clone or download
gyuho README: update travis links
Signed-off-by: Gyuho Lee <>
Latest commit 51ce9a7 Aug 9, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
code *: update import paths to "etcd-io" Aug 8, 2018
.travis.yml *: update import paths to "etcd-io" Aug 8, 2018
DCO update CoC and legalese Jan 4, 2018
LICENSE initial commit Jun 20, 2016
Makefile test: add travis Jun 21, 2016
NOTICE update CoC and legalese Jan 4, 2018 README: update travis links Aug 8, 2018
gofail.go *: update import paths to "etcd-io" Aug 8, 2018


Build Status

An implementation of failpoints for golang.

Add a failpoint

Failpoints are special comments that include a failpoint variable declaration and some trigger code,

func someFunc() string {
	// gofail: var SomeFuncString string
	// // this is called when the failpoint is triggered
	// return SomeFuncString
	return "default"

Build with failpoints

Building with failpoints will translate gofail comments in place to code that accesses the gofail runtime.

Call gofail in the directory with failpoints to generate gofail runtime bindings, then build as usual,

gofail enable
go build cmd/

The translated code looks something like,

func someFunc() string {
        if vSomeFuncString, __fpErr := __fp_SomeFuncString.Acquire(); __fpErr == nil { defer __fp_SomeFuncString.Release(); SomeFuncString, __fpTypeOK := vSomeFuncString.(string); if !__fpTypeOK { goto __badTypeSomeFuncString}
		// this is called when the failpoint is triggered
		return SomeFuncString; __badTypeSomeFuncString: __fp_SomeFuncString.BadType(vSomeFuncString, "string"); };
        return "default"

To disable failpoints and revert to the original code,

gofail disable

Triggering a failpoint

After building with failpoints enabled, the program's failpoints can be activated so they may trigger when evaluated.

Command line

From the command line, trigger the failpoint to set SomeFuncString to hello,

GOFAIL_FAILPOINTS='my/package/path/SomeFuncString=return("hello")' ./cmd

Multiple failpoints are set by using ';' for a delimiter,

GOFAIL_FAILPOINTS='failpoint1=return("hello");failpoint2=sleep(10)' ./cmd

HTTP endpoint

First, enable the HTTP server from the command line,

GOFAIL_HTTP="" ./cmd

Activate a failpoint with curl,

$ curl -XPUT -d'return("hello")'

List the failpoints,

$ curl

Deactivate a failpoint,

$ curl -XDELETE

Unit tests

From a unit test,

import (

	gofail ""

func TestWhatever(t *testing.T) {
	gofail.Enable("my/package/path/SomeFuncString", `return("hello")`)
	defer gofail.Disable("my/package/path/SomeFuncString")