-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathunary_interceptor_test.go
55 lines (45 loc) · 1.22 KB
/
unary_interceptor_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
package zerolog
import (
"bytes"
"testing"
"github.com/philip-bui/grpc-zerolog/test"
"github.com/rs/zerolog"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)
type TestUnaryInterceptorSuite struct {
suite.Suite
out *bytes.Buffer
log zerolog.Logger
client *test.TestClient
}
func TestUnaryServerInterceptor(t *testing.T) {
assert.NotNil(t, UnaryInterceptor())
}
func (s *TestUnaryInterceptorSuite) SetupSuite() {
s.out = &bytes.Buffer{}
s.log = zerolog.New(s.out)
go func() {
test.StartServer(NewUnaryServerInterceptorWithLogger(&s.log))
}()
s.client = test.GetClient()
}
func (s *TestUnaryInterceptorSuite) SetupTest() {
s.out = &bytes.Buffer{}
s.log = zerolog.New(s.out)
}
func TestUnaryInterceptor(t *testing.T) {
suite.Run(t, new(TestUnaryInterceptorSuite))
}
func (s *TestUnaryInterceptorSuite) TestUnaryClientInterceptor() {
resp, err := s.client.SendReq()
s.NoError(err, "Expected no errors")
s.Equal(s.client.ExampleReq.Test, resp.Test, "Expected request and response to be the same")
s.NotEmpty(s.out.String())
}
func (s *TestUnaryInterceptorSuite) TestUnaryClientInterceptorError() {
resp, err := s.client.SendErr()
s.Error(err)
s.Empty(resp)
s.NotEmpty(s.out.String())
}