MCPcopy
hub / github.com/nats-io/nats.go / TestEncProtoNilRequest

Function TestEncProtoNilRequest

test/protobuf_test.go:71–98  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

69}
70
71func TestEncProtoNilRequest(t *testing.T) {
72 s := RunServerOnPort(TEST_PORT)
73 defer s.Shutdown()
74
75 ec := NewProtoEncodedConn(t)
76 defer ec.Close()
77
78 testPerson := &pb.Person{Name: "Anatolii", Age: 25, Address: "Ukraine, Nikolaev"}
79
80 //Subscribe with empty interface shouldn't failed on empty message
81 ec.Subscribe("nil_test", func(_, reply string, _ any) {
82 ec.Publish(reply, testPerson)
83 })
84
85 resp := new(pb.Person)
86
87 //Request with nil argument shouldn't failed with nil argument
88 err := ec.Request("nil_test", nil, resp, 100*time.Millisecond)
89 ec.Flush()
90
91 if err != nil {
92 t.Error("Fail to send empty message via encoded proto connection")
93 }
94
95 if !reflect.DeepEqual(testPerson.ProtoReflect(), resp.ProtoReflect()) {
96 t.Error("Fail to receive encoded response")
97 }
98}
99
100func BenchmarkProtobufMarshalStruct(b *testing.B) {
101 me := &pb.Person{Name: "derek", Age: 22, Address: "140 New Montgomery St"}

Callers

nothing calls this directly

Calls 9

ProtoReflectMethod · 0.95
NewProtoEncodedConnFunction · 0.85
RunServerOnPortFunction · 0.70
SubscribeMethod · 0.65
PublishMethod · 0.65
ErrorMethod · 0.65
CloseMethod · 0.45
RequestMethod · 0.45
FlushMethod · 0.45

Tested by

no test coverage detected