-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrequest_server_internal_test.go
57 lines (39 loc) · 1.31 KB
/
request_server_internal_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
53
54
55
56
57
package grpcsteps
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestServerRequestReflectorPlanner_WithTimeout(t *testing.T) {
t.Parallel()
p := newServerRequestPlanner((*unaryExpectation)(nil))
err := p.WithTimeout(0)
expected := `grpc service request does not have timeout`
assert.EqualError(t, err, expected)
}
func TestServerRequestPlannerInContext(t *testing.T) {
t.Parallel()
ctx := context.Background()
// Case 1: no planner in context.
assert.Equal(t, missingServerRequestPlanner{}, serverRequestPlannerFromContext(ctx))
// Case 2: request in context.
ctx = newServerRequestPlannerContext(ctx, nil)
assert.Equal(t, &serverRequestReflectorPlanner{}, serverRequestPlannerFromContext(ctx))
}
func TestMissingServerRequestPlanner(t *testing.T) {
t.Parallel()
expected := `no service request in context, did you forget to setup a gprc request in the scenario?
For example:
When "item-service" receives a grpc request "/grpctest.ItemService/GetItem" with payload:
"""
{
"id": 42
}
"""
`
p := missingServerRequestPlanner{}
assert.EqualError(t, p.WithHeader("", nil), expected)
assert.EqualError(t, p.WithTimeout(0), expected)
assert.EqualError(t, p.Return(""), expected)
assert.EqualError(t, p.ReturnError(0, ""), expected)
}