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

Function TestEncBuiltinJsonMarshalStruct

test/json_test.go:197–226  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

195}
196
197func TestEncBuiltinJsonMarshalStruct(t *testing.T) {
198 s := RunServerOnPort(TEST_PORT)
199 defer s.Shutdown()
200
201 ec := NewJsonEncodedConn(t)
202 defer ec.Close()
203 ch := make(chan bool)
204
205 me := &person{Name: "derek", Age: 22, Address: "140 New Montgomery St"}
206 me.Children = make(map[string]*person)
207
208 me.Children["sam"] = &person{Name: "sam", Age: 19, Address: "140 New Montgomery St"}
209 me.Children["meg"] = &person{Name: "meg", Age: 17, Address: "140 New Montgomery St"}
210
211 me.Assets = make(map[string]uint)
212 me.Assets["house"] = 1000
213 me.Assets["car"] = 100
214
215 ec.Subscribe("json_struct", func(p *person) {
216 if !reflect.DeepEqual(p, me) {
217 t.Fatal("Did not receive the correct struct response")
218 }
219 ch <- true
220 })
221
222 ec.Publish("json_struct", me)
223 if e := Wait(ch); e != nil {
224 t.Fatal("Did not receive the message")
225 }
226}
227
228func BenchmarkJsonMarshalStruct(b *testing.B) {
229 me := &person{Name: "derek", Age: 22, Address: "140 New Montgomery St"}

Callers

nothing calls this directly

Calls 6

NewJsonEncodedConnFunction · 0.85
RunServerOnPortFunction · 0.70
WaitFunction · 0.70
SubscribeMethod · 0.65
PublishMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected