-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
46 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// when multiple interceptors added, the order is reversed | ||
package trap | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/xhd2015/xgo/runtime/core" | ||
"github.com/xhd2015/xgo/runtime/trap" | ||
) | ||
|
||
func TestTrapOverlay(t *testing.T) { | ||
trap.AddInterceptor(&trap.Interceptor{ | ||
Pre: func(ctx context.Context, f *core.FuncInfo, args, result core.Object) (data interface{}, err error) { | ||
if f.IdentityName == "testOverlay" { | ||
panic("first trap should not be called") | ||
} | ||
return nil, nil | ||
}, | ||
}) | ||
|
||
// overlay | ||
var trapCalled bool | ||
trap.AddInterceptor(&trap.Interceptor{ | ||
Pre: func(ctx context.Context, f *core.FuncInfo, args, result core.Object) (data interface{}, err error) { | ||
if f.IdentityName == "testOverlay" { | ||
trapCalled = true | ||
return nil, trap.ErrAbort | ||
} | ||
return | ||
}, | ||
}) | ||
testOverlay() | ||
|
||
if !trapCalled { | ||
t.Fatalf("expect trap to have been called, actually not called") | ||
} | ||
} | ||
|
||
func testOverlay() { | ||
|
||
} |