forked from qlik-oss/enigma-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interceptors_test.go
48 lines (37 loc) · 1.36 KB
/
interceptors_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
40
41
42
43
44
45
46
47
48
package enigma
import (
"context"
"github.com/stretchr/testify/assert"
"testing"
)
func TestBuildInterceptorChain(t *testing.T) {
log := ""
finalFunc := func(ctx context.Context, invocation *Invocation) *InvocationResponse {
log += "<jsonrpc>"
return nil
}
interceptor1 := func(ctx context.Context, invocation *Invocation, next InterceptorContinuation) *InvocationResponse {
log += "<before1>"
response := next(ctx, invocation)
log += "<after1>"
return response
}
interceptor2 := func(ctx context.Context, invocation *Invocation, next InterceptorContinuation) *InvocationResponse {
log += "<before2>"
response := next(ctx, invocation)
log += "<after2>"
return response
}
interceptorChain0 := buildInterceptorChain([]Interceptor{}, finalFunc)
interceptorChain1 := buildInterceptorChain([]Interceptor{interceptor1}, finalFunc)
interceptorChain2 := buildInterceptorChain([]Interceptor{interceptor1, interceptor2}, finalFunc)
log = ""
interceptorChain0(nil, &Invocation{RemoteObject: nil, Method: "", Params: nil})
assert.Equal(t, "<jsonrpc>", log)
log = ""
interceptorChain1(nil, &Invocation{RemoteObject: nil, Method: "", Params: nil})
assert.Equal(t, "<before1><jsonrpc><after1>", log)
log = ""
interceptorChain2(nil, &Invocation{RemoteObject: nil, Method: "", Params: nil})
assert.Equal(t, "<before1><before2><jsonrpc><after2><after1>", log)
}