Skip to content

Commit dc78417

Browse files
authored
test: add trace_test.go (#497)
* test: add trace_test.go * refactor: rename test title
1 parent 81d63bd commit dc78417

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

lambda/handlertrace/trace_test.go

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package handlertrace
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"testing"
7+
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func TestTrace(t *testing.T) {
12+
ctx := context.Background()
13+
14+
requestCall := 0
15+
responseCall := 0
16+
17+
existedContext := context.WithValue(ctx, handlerTraceKey{}, HandlerTrace{
18+
RequestEvent: func(ctx context.Context, event interface{}) {
19+
requestCall += 1
20+
},
21+
ResponseEvent: func(ctx context.Context, event interface{}) {
22+
responseCall += 1
23+
},
24+
})
25+
26+
trace := HandlerTrace{
27+
RequestEvent: func(ctx context.Context, event interface{}) {
28+
requestCall += 1
29+
},
30+
ResponseEvent: func(ctx context.Context, event interface{}) {
31+
responseCall += 1
32+
},
33+
}
34+
35+
ctxWithTrace := NewContext(existedContext, trace)
36+
traceFromCtx := FromContext(ctxWithTrace)
37+
38+
traceFromCtx.RequestEvent(ctxWithTrace, nil)
39+
assert.Equal(t, requestCall, 2)
40+
41+
traceFromCtx.ResponseEvent(ctxWithTrace, nil)
42+
fmt.Println(responseCall)
43+
assert.Equal(t, responseCall, 2)
44+
}

0 commit comments

Comments
 (0)