Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ An implementation of [failpoints][failpoint] for Golang. Fail points are used to

The <type> argument specifies which action to take; it can be one of:

- off: Take no action (does not trigger failpoint code)
- off: Take no action (does not trigger failpoint code; `Eval` returns `ErrNotAllowed`)
- return: Trigger failpoint with specified argument
- sleep: Sleep the specified number of milliseconds
- panic: Panic
Expand Down
32 changes: 32 additions & 0 deletions failpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,38 @@ func testPanic() {
_, _ = failpoint.Eval("test-panic")
}

func TestOff(t *testing.T) {
tests := []struct {
terms string
want []failpoint.Value
}{
{"off", []failpoint.Value{nil, nil}},
{"off->return(2)", []failpoint.Value{nil, nil}},
{"1*return(1)->off", []failpoint.Value{1, nil, nil}},
{"1*off->return(2)", []failpoint.Value{nil, 2, 2}},
{"0*off->return(2)", []failpoint.Value{2, 2}},
{"return", []failpoint.Value{struct{}{}, struct{}{}}},
}
for _, tt := range tests {
t.Run(tt.terms, func(t *testing.T) {
var fps failpoint.Failpoints
require.NoError(t, fps.Enable("test-off", tt.terms))
for _, want := range tt.want {
value, err := fps.Eval("test-off")
if want == nil {
require.ErrorIs(t, err, failpoint.ErrNotAllowed)
} else {
require.NoError(t, err)
}
require.Equal(t, want, value)
}
status, err := fps.Status("test-off")
require.NoError(t, err)
require.Equal(t, tt.terms, status)
})
}
}

func TestCall(t *testing.T) {
var capturedArg int
require.NoError(t, failpoint.EnableCall("test", func(a int) {
Expand Down
2 changes: 1 addition & 1 deletion terms.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ var actMap = map[string]actFunc{

func (t *term) do() (interface{}, error) { return t.act(t) }

func actOff(t *term) (interface{}, error) { return nil, nil }
func actOff(t *term) (interface{}, error) { return nil, ErrNotAllowed }

func actReturn(t *term) (interface{}, error) { return t.val, nil }

Expand Down
Loading