-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathcontext_test.go
52 lines (46 loc) · 1.14 KB
/
context_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
49
50
51
52
package validate
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestContext_ExtractOperationType(t *testing.T) {
var testCases = []struct {
Ctx context.Context //nolint: containedctx
ExpectedOpType operationType
}{
{
Ctx: WithOperationRequest(context.Background()),
ExpectedOpType: request,
},
{
Ctx: WithOperationResponse(context.Background()),
ExpectedOpType: response,
},
{
Ctx: context.Background(),
ExpectedOpType: none,
},
{
Ctx: context.WithValue(context.Background(), validateCtxKey("dummy"), "dummy val"),
ExpectedOpType: none,
},
{
Ctx: context.WithValue(context.Background(), operationTypeKey, "dummy val"),
ExpectedOpType: none,
},
{
Ctx: context.WithValue(context.Background(), operationTypeKey, operationType("dummy val")),
ExpectedOpType: none,
},
}
for idx, toPin := range testCases {
tc := toPin
t.Run(fmt.Sprintf("TestCase #%d", idx), func(t *testing.T) {
t.Parallel()
op := extractOperationType(tc.Ctx)
assert.Equal(t, tc.ExpectedOpType, op)
})
}
}