forked from pingcap/failpoint
/
failpoint_test.go
39 lines (32 loc) · 904 Bytes
/
failpoint_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package failpoint_test
import (
"context"
"testing"
. "github.com/pingcap/check"
"github.com/pingcap/failpoint"
)
func TestFailpoint(t *testing.T) {
TestingT(t)
}
var _ = Suite(&failpointSuite{})
type failpointSuite struct{}
func (s *failpointSuite) TestWithHook(c *C) {
ctx := failpoint.WithHook(context.Background(), func(ctx context.Context, fpname string) bool {
return false
})
ok, val := failpoint.EvalContext(ctx, "unit-test")
c.Assert(ok, IsFalse)
c.Assert(val, IsNil)
ctx = failpoint.WithHook(context.Background(), func(ctx context.Context, fpname string) bool {
return true
})
err := failpoint.Enable("TestWithHook-test-1", "return(1)")
defer func() {
err := failpoint.Disable("TestWithHook-test-1")
c.Assert(err, IsNil)
}()
c.Assert(err, IsNil)
ok, val = failpoint.EvalContext(ctx, "TestWithHook-test-1")
c.Assert(ok, IsTrue)
c.Assert(val.(int), Equals, 1)
}