@@ -90,6 +90,110 @@ func TestCustomErrorMarshaling(t *testing.T) {
90
90
}
91
91
}
92
92
93
+ func TestXRayCausePlumbing (t * testing.T ) {
94
+ errors := []error {
95
+ errors .New ("barf" ),
96
+ messages.InvokeResponse_Error {
97
+ Type : "yoloError" ,
98
+ Message : "hello yolo" ,
99
+ StackTrace : []* messages.InvokeResponse_Error_StackFrame {
100
+ {Label : "yolo" , Path : "yolo" , Line : 2 },
101
+ {Label : "hi" , Path : "hello/hello" , Line : 12 },
102
+ },
103
+ },
104
+ messages.InvokeResponse_Error {
105
+ Type : "yoloError" ,
106
+ Message : "hello yolo" ,
107
+ StackTrace : []* messages.InvokeResponse_Error_StackFrame {
108
+ {Label : "hi" , Path : "hello/hello" , Line : 12 },
109
+ {Label : "hihi" , Path : "hello/hello" , Line : 13 },
110
+ {Label : "yolo" , Path : "yolo" , Line : 2 },
111
+ {Label : "hi" , Path : "hello/hello" , Line : 14 },
112
+ },
113
+ },
114
+ messages.InvokeResponse_Error {
115
+ Type : "yoloError" ,
116
+ Message : "hello yolo" ,
117
+ StackTrace : []* messages.InvokeResponse_Error_StackFrame {},
118
+ },
119
+ messages.InvokeResponse_Error {
120
+ Type : "yoloError" ,
121
+ Message : "hello yolo" ,
122
+ },
123
+ }
124
+ wd , _ := os .Getwd ()
125
+ expected := []string {
126
+ `{
127
+ "working_directory":"` + wd + `",
128
+ "paths": [],
129
+ "exceptions": [{
130
+ "type": "errorString",
131
+ "message": "barf",
132
+ "stack": []
133
+ }]
134
+ }` ,
135
+ `{
136
+ "working_directory":"` + wd + `",
137
+ "paths": ["yolo", "hello/hello"],
138
+ "exceptions": [{
139
+ "type": "yoloError",
140
+ "message": "hello yolo",
141
+ "stack": [
142
+ {"label": "yolo", "path": "yolo", "line": 2},
143
+ {"label": "hi", "path": "hello/hello", "line": 12}
144
+ ]
145
+ }]
146
+ }` ,
147
+ `{
148
+ "working_directory":"` + wd + `",
149
+ "paths": ["hello/hello", "yolo"],
150
+ "exceptions": [{
151
+ "type": "yoloError",
152
+ "message": "hello yolo",
153
+ "stack": [
154
+ {"label": "hi", "path": "hello/hello", "line": 12},
155
+ {"label": "hihi", "path": "hello/hello", "line": 13},
156
+ {"label": "yolo", "path": "yolo", "line": 2},
157
+ {"label": "hi", "path": "hello/hello", "line": 14}
158
+ ]
159
+ }]
160
+ }` ,
161
+ `{
162
+ "working_directory":"` + wd + `",
163
+ "paths": [],
164
+ "exceptions": [{
165
+ "type": "yoloError",
166
+ "message": "hello yolo",
167
+ "stack": []
168
+ }]
169
+ }` ,
170
+ `{
171
+ "working_directory":"` + wd + `",
172
+ "paths": [],
173
+ "exceptions": [{
174
+ "type": "yoloError",
175
+ "message": "hello yolo",
176
+ "stack": []
177
+ }]
178
+ }` ,
179
+ }
180
+ require .Equal (t , len (errors ), len (expected ))
181
+ ts , record := runtimeAPIServer (`` , len (errors ))
182
+ defer ts .Close ()
183
+ n := 0
184
+ handler := NewHandler (func () error {
185
+ defer func () { n ++ }()
186
+ return errors [n ]
187
+ })
188
+ endpoint := strings .Split (ts .URL , "://" )[1 ]
189
+ expectedError := fmt .Sprintf ("failed to GET http://%s/2018-06-01/runtime/invocation/next: got unexpected status code: 410" , endpoint )
190
+ assert .EqualError (t , startRuntimeAPILoop (endpoint , handler ), expectedError )
191
+ for i := range errors {
192
+ assert .JSONEq (t , expected [i ], string (record .xrayCauses [i ]))
193
+ }
194
+
195
+ }
196
+
93
197
func TestRuntimeAPIContextPlumbing (t * testing.T ) {
94
198
handler := NewHandler (func (ctx context.Context ) (interface {}, error ) {
95
199
lc , _ := lambdacontext .FromContext (ctx )
@@ -271,6 +375,7 @@ type requestRecord struct {
271
375
nPosts int
272
376
responses [][]byte
273
377
contentTypes []string
378
+ xrayCauses []string
274
379
}
275
380
276
381
type eventMetadata struct {
@@ -336,6 +441,7 @@ func runtimeAPIServer(eventPayload string, failAfter int, overrides ...eventMeta
336
441
w .WriteHeader (http .StatusAccepted )
337
442
record .responses = append (record .responses , response .Bytes ())
338
443
record .contentTypes = append (record .contentTypes , r .Header .Get ("Content-Type" ))
444
+ record .xrayCauses = append (record .xrayCauses , r .Header .Get (headerXRayErrorCause ))
339
445
default :
340
446
w .WriteHeader (http .StatusBadRequest )
341
447
}
0 commit comments