forked from adamlaska/boulder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.go
More file actions
99 lines (85 loc) · 3.08 KB
/
errors_test.go
File metadata and controls
99 lines (85 loc) · 3.08 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package grpc
import (
"context"
"fmt"
"net"
"testing"
"time"
"google.golang.org/grpc"
"github.com/jmhodges/clock"
berrors "github.com/letsencrypt/boulder/errors"
"github.com/letsencrypt/boulder/grpc/test_proto"
testproto "github.com/letsencrypt/boulder/grpc/test_proto"
"github.com/letsencrypt/boulder/identifier"
"github.com/letsencrypt/boulder/metrics"
"github.com/letsencrypt/boulder/test"
)
type errorServer struct {
test_proto.UnimplementedChillerServer
err error
}
func (s *errorServer) Chill(_ context.Context, _ *testproto.Time) (*testproto.Time, error) {
return nil, s.err
}
func TestErrorWrapping(t *testing.T) {
serverMetrics := NewServerMetrics(metrics.NoopRegisterer)
si := newServerInterceptor(serverMetrics, clock.NewFake())
ci := clientInterceptor{time.Second, NewClientMetrics(metrics.NoopRegisterer), clock.NewFake()}
srv := grpc.NewServer(grpc.UnaryInterceptor(si.intercept))
es := &errorServer{}
testproto.RegisterChillerServer(srv, es)
lis, err := net.Listen("tcp", "127.0.0.1:")
test.AssertNotError(t, err, "Failed to create listener")
go func() { _ = srv.Serve(lis) }()
defer srv.Stop()
conn, err := grpc.Dial(
lis.Addr().String(),
grpc.WithInsecure(),
grpc.WithUnaryInterceptor(ci.intercept),
)
test.AssertNotError(t, err, "Failed to dial grpc test server")
client := testproto.NewChillerClient(conn)
es.err = berrors.MalformedError("yup")
_, err = client.Chill(context.Background(), &testproto.Time{})
test.Assert(t, err != nil, fmt.Sprintf("nil error returned, expected: %s", err))
test.AssertDeepEquals(t, err, es.err)
test.AssertEquals(t, wrapError(context.Background(), nil), nil)
test.AssertEquals(t, unwrapError(nil, nil), nil)
}
// TestSubErrorWrapping tests that a boulder error with suberrors can be
// correctly wrapped and unwrapped across the RPC layer.
func TestSubErrorWrapping(t *testing.T) {
serverMetrics := NewServerMetrics(metrics.NoopRegisterer)
si := newServerInterceptor(serverMetrics, clock.NewFake())
ci := clientInterceptor{time.Second, NewClientMetrics(metrics.NoopRegisterer), clock.NewFake()}
srv := grpc.NewServer(grpc.UnaryInterceptor(si.intercept))
es := &errorServer{}
testproto.RegisterChillerServer(srv, es)
lis, err := net.Listen("tcp", "127.0.0.1:")
test.AssertNotError(t, err, "Failed to create listener")
go func() { _ = srv.Serve(lis) }()
defer srv.Stop()
conn, err := grpc.Dial(
lis.Addr().String(),
grpc.WithInsecure(),
grpc.WithUnaryInterceptor(ci.intercept),
)
test.AssertNotError(t, err, "Failed to dial grpc test server")
client := testproto.NewChillerClient(conn)
subErrors := []berrors.SubBoulderError{
{
Identifier: identifier.DNSIdentifier("chillserver.com"),
BoulderError: &berrors.BoulderError{
Type: berrors.RejectedIdentifier,
Detail: "2 ill 2 chill",
},
},
}
es.err = (&berrors.BoulderError{
Type: berrors.Malformed,
Detail: "malformed chill req",
}).WithSubErrors(subErrors)
_, err = client.Chill(context.Background(), &testproto.Time{})
test.Assert(t, err != nil, fmt.Sprintf("nil error returned, expected: %s", err))
test.AssertDeepEquals(t, err, es.err)
}