You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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,
funcsomeFunc() string {
// gofail: var SomeFuncString string// // this is called when the failpoint is triggered// return SomeFuncStringreturn"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,
funcsomeFunc() string {
ifvSomeFuncString, __fpErr:=__fp_SomeFuncString.Acquire(); __fpErr==nil { SomeFuncString, __fpTypeOK:=vSomeFuncString.(string); if!__fpTypeOK { goto __badTypeSomeFuncString}
// this is called when the failpoint is triggeredreturnSomeFuncString; 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,