MCPcopy Index your code
hub / github.com/etcd-io/gofail

github.com/etcd-io/gofail @v0.2.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.2.0 ↗ · + Follow
88 symbols 196 edges 17 files 21 documented · 24% 4 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

gofail

Build Status

An implementation of failpoints for golang. Please read design.md for a deeper understanding.

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 { SomeFuncString, __fpTypeOK := vSomeFuncString.(string); if !__fpTypeOK { goto __badTypeSomeFuncString} 
         // this is called when the failpoint is triggered
         return SomeFuncString; goto __nomockSomeFuncString; __badTypeSomeFuncString: __fp_SomeFuncString.BadType(vSomeFuncString, "string"); __nomockSomeFuncString: };
    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='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="127.0.0.1:1234" ./cmd

Activate a failpoint with curl,

$ curl http://127.0.0.1:1234/SomeFuncString -XPUT -d'return("hello")'

List the failpoints,

$ curl http://127.0.0.1:1234/SomeFuncString=return("hello")

Retrieve the execution count of a failpoint,

$curl http://127.0.0.1:1234/SomeFuncString/count -XGET

Deactivate a failpoint,

$ curl http://127.0.0.1:1234/SomeFuncString -XDELETE

Unit tests

From a unit test,

import (
    "testing"

    gofail "go.etcd.io/gofail/runtime"
)

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

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Name
called by 5
code/failpoint.go
Write
called by 5
code/binding.go
newTerms
called by 4
runtime/terms.go
String
called by 4
runtime/terms.go
eval
called by 4
runtime/terms.go
NewFailpoint
called by 3
runtime/failpoint.go
parseFailpoints
called by 3
runtime/runtime.go
Status
called by 3
runtime/runtime.go

Shape

Function 55
Method 21
Struct 9
FuncType 2
Interface 1

Languages

Go100%

Modules by API surface

runtime/terms.go27 symbols
code/failpoint.go9 symbols
runtime/runtime.go8 symbols
runtime/failpoint.go7 symbols
gofail.go7 symbols
code/rewrite.go5 symbols
runtime/http.go4 symbols
runtime/terms_test.go3 symbols
runtime/failpoint_test.go3 symbols
integration/sleep/failpoints/failpoints.go3 symbols
examples/examples.go3 symbols
code/binding.go3 symbols

For agents

$ claude mcp add gofail \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact