@@ -302,7 +302,7 @@ func doGRPCTest(t *testing.T, l net.Listener, sec *atest.Secure, desc *atest.GRP
302
302
Body : "{}" ,
303
303
},
304
304
Expect : atest.Response {
305
- Body : getJSONOrCache ("unaryneq" , & testsrv.HelloReply {
305
+ Body : getJSONOrCache (nil , & testsrv.HelloReply {
306
306
Message : "Happy!" ,
307
307
}),
308
308
},
@@ -376,7 +376,7 @@ func doGRPCTest(t *testing.T, l net.Listener, sec *atest.Secure, desc *atest.GRP
376
376
Body : getJSONOrCache ("stream" , nil ),
377
377
},
378
378
Expect : atest.Response {
379
- Body : getJSONOrCache ("streamneq" , []* testsrv.StreamMessage {
379
+ Body : getJSONOrCache (nil , []* testsrv.StreamMessage {
380
380
{MsgID : 1 , ExpectLen : 2 },
381
381
{MsgID : 2 , ExpectLen : 2 },
382
382
}),
@@ -394,7 +394,7 @@ func doGRPCTest(t *testing.T, l net.Listener, sec *atest.Secure, desc *atest.GRP
394
394
Body : getJSONOrCache ("stream" , nil ),
395
395
},
396
396
Expect : atest.Response {
397
- Body : getJSONOrCache ("streamneq" , []* testsrv.StreamMessage {
397
+ Body : getJSONOrCache (nil , []* testsrv.StreamMessage {
398
398
{MsgID : 4 , ExpectLen : 3 },
399
399
{MsgID : 5 , ExpectLen : 3 },
400
400
{MsgID : 6 , ExpectLen : 3 },
@@ -479,7 +479,7 @@ func doGRPCTest(t *testing.T, l net.Listener, sec *atest.Secure, desc *atest.GRP
479
479
}),
480
480
},
481
481
Expect : atest.Response {
482
- Body : getJSONOrCache ("advancedneq" ,
482
+ Body : getJSONOrCache (nil ,
483
483
& testsrv.AdvancedType {
484
484
Int32Array : []int32 {rand .Int31 (), rand .Int31 ()},
485
485
Int64Array : []int64 {rand .Int63 (), rand .Int63 ()},
@@ -601,13 +601,18 @@ func TestAPINameMatch(t *testing.T) {
601
601
)
602
602
}
603
603
604
- func getJSONOrCache (k string , s any ) (msg string ) {
605
- v , ok := cache .Load (k )
606
- if ok {
604
+ // getJSONOrCache can store the JSON string of value.
605
+ //
606
+ // Let key be nil represent not using cache.
607
+ func getJSONOrCache (key any , value any ) (msg string ) {
608
+ v , ok := cache .Load (key )
609
+ if ok && key != nil {
607
610
return v .(string )
608
611
}
609
- b , _ := json .Marshal (s )
612
+ b , _ := json .Marshal (value )
610
613
msg = string (b )
611
- cache .Store (k , msg )
614
+ if key != nil {
615
+ cache .Store (key , msg )
616
+ }
612
617
return
613
618
}
0 commit comments