@@ -29,6 +29,7 @@ import (
29
29
"github.com/stretchr/testify/require"
30
30
"go.uber.org/zap"
31
31
"google.golang.org/grpc"
32
+ "google.golang.org/grpc/codes"
32
33
"google.golang.org/grpc/status"
33
34
34
35
"github.com/jaegertracing/jaeger/cmd/query/app/querysvc"
@@ -40,12 +41,9 @@ import (
40
41
)
41
42
42
43
var (
43
- errStorageMsgGRPC = "Storage error"
44
- errStorageGRPC = errors .New (errStorageMsgGRPC )
45
- errStatusStorageGRPC = status .Error (2 , errStorageMsgGRPC )
44
+ errStorageGRPC = errors .New ("storage error" )
46
45
47
- mockTraceIDgrpc = model .NewTraceID (0 , 123456 )
48
- mockTraceGRPC = & model.Trace {
46
+ mockTraceGRPC = & model.Trace {
49
47
Spans : []* model.Span {
50
48
{
51
49
TraceID : mockTraceID ,
@@ -207,7 +205,7 @@ func TestGetTraceSuccessGRPC(t *testing.T) {
207
205
Return (mockTrace , nil ).Once ()
208
206
209
207
res , err := client .GetTrace (context .Background (), & api_v2.GetTraceRequest {
210
- TraceID : mockTraceIDgrpc ,
208
+ TraceID : mockTraceID ,
211
209
})
212
210
213
211
spanResChunk , _ := res .Recv ()
@@ -218,22 +216,27 @@ func TestGetTraceSuccessGRPC(t *testing.T) {
218
216
})
219
217
}
220
218
219
+ func assertGRPCError (t * testing.T , err error , code codes.Code , msg string ) {
220
+ s , ok := status .FromError (err )
221
+ require .True (t , ok , "expecting gRPC status" )
222
+ assert .Equal (t , code , s .Code ())
223
+ assert .Contains (t , s .Message (), msg )
224
+ }
225
+
221
226
func TestGetTraceDBFailureGRPC (t * testing.T ) {
222
227
withServerAndClient (t , func (server * grpcServer , client * grpcClient ) {
223
228
224
229
server .spanReader .On ("GetTrace" , mock .AnythingOfType ("*context.valueCtx" ), mock .AnythingOfType ("model.TraceID" )).
225
230
Return (nil , errStorageGRPC ).Once ()
226
231
227
232
res , err := client .GetTrace (context .Background (), & api_v2.GetTraceRequest {
228
- TraceID : mockTraceIDgrpc ,
233
+ TraceID : mockTraceID ,
229
234
})
230
235
assert .NoError (t , err )
231
236
232
237
spanResChunk , err := res .Recv ()
233
-
234
- assert .EqualError (t , err , errStatusStorageGRPC .Error ())
238
+ assertGRPCError (t , err , codes .Internal , "failed to fetch spans from the backend" )
235
239
assert .Nil (t , spanResChunk )
236
-
237
240
})
238
241
239
242
}
@@ -248,14 +251,12 @@ func TestGetTraceNotFoundGRPC(t *testing.T) {
248
251
Return (nil , spanstore .ErrTraceNotFound ).Once ()
249
252
250
253
res , err := client .GetTrace (context .Background (), & api_v2.GetTraceRequest {
251
- TraceID : mockTraceIDgrpc ,
254
+ TraceID : mockTraceID ,
252
255
})
253
256
assert .NoError (t , err )
254
257
spanResChunk , err := res .Recv ()
255
-
256
- assert .Errorf (t , err , spanstore .ErrTraceNotFound .Error ())
258
+ assertGRPCError (t , err , codes .NotFound , "trace not found" )
257
259
assert .Nil (t , spanResChunk )
258
-
259
260
})
260
261
}
261
262
@@ -267,7 +268,7 @@ func TestArchiveTraceSuccessGRPC(t *testing.T) {
267
268
Return (nil ).Times (2 )
268
269
269
270
_ , err := client .ArchiveTrace (context .Background (), & api_v2.ArchiveTraceRequest {
270
- TraceID : mockTraceIDgrpc ,
271
+ TraceID : mockTraceID ,
271
272
})
272
273
273
274
assert .NoError (t , err )
@@ -282,11 +283,10 @@ func TestArchiveTraceNotFoundGRPC(t *testing.T) {
282
283
Return (nil , spanstore .ErrTraceNotFound ).Once ()
283
284
284
285
_ , err := client .ArchiveTrace (context .Background (), & api_v2.ArchiveTraceRequest {
285
- TraceID : mockTraceIDgrpc ,
286
+ TraceID : mockTraceID ,
286
287
})
287
288
288
- assert .Errorf (t , err , spanstore .ErrTraceNotFound .Error ())
289
-
289
+ assertGRPCError (t , err , codes .NotFound , "trace not found" )
290
290
})
291
291
}
292
292
@@ -299,12 +299,10 @@ func TestArchiveTraceFailureGRPC(t *testing.T) {
299
299
Return (errStorageGRPC ).Times (2 )
300
300
301
301
_ , err := client .ArchiveTrace (context .Background (), & api_v2.ArchiveTraceRequest {
302
- TraceID : mockTraceIDgrpc ,
302
+ TraceID : mockTraceID ,
303
303
})
304
304
305
- storageErr := status .Error (2 , "[Storage error, Storage error]" )
306
- assert .EqualError (t , err , storageErr .Error ())
307
-
305
+ assertGRPCError (t , err , codes .Internal , "failed to archive trace" )
308
306
})
309
307
}
310
308
@@ -408,7 +406,7 @@ func TestGetServicesFailureGRPC(t *testing.T) {
408
406
server .spanReader .On ("GetServices" , mock .AnythingOfType ("*context.valueCtx" )).Return (nil , errStorageGRPC ).Once ()
409
407
_ , err := client .GetServices (context .Background (), & api_v2.GetServicesRequest {})
410
408
411
- assert . EqualError (t , err , errStatusStorageGRPC . Error () )
409
+ assertGRPCError (t , err , codes . Internal , "failed to fetch services" )
412
410
})
413
411
}
414
412
@@ -450,7 +448,7 @@ func TestGetOperationsFailureGRPC(t *testing.T) {
450
448
Service : "trifle" ,
451
449
})
452
450
453
- assert . EqualError (t , err , errStatusStorageGRPC . Error () )
451
+ assertGRPCError (t , err , codes . Internal , "failed to fetch operations" )
454
452
})
455
453
}
456
454
@@ -482,7 +480,7 @@ func TestGetDependenciesFailureGRPC(t *testing.T) {
482
480
EndTime : endTs ,
483
481
})
484
482
485
- assert . EqualError (t , err , errStatusStorageGRPC . Error () )
483
+ assertGRPCError (t , err , codes . Internal , "failed to fetch dependencies" )
486
484
})
487
485
}
488
486
0 commit comments