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

Function TestEncBuiltinGobMarshalStruct

test/gob_test.go:77–106  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

75}
76
77func TestEncBuiltinGobMarshalStruct(t *testing.T) {
78 s := RunServerOnPort(TEST_PORT)
79 defer s.Shutdown()
80
81 ec := NewGobEncodedConn(t)
82 defer ec.Close()
83 ch := make(chan bool)
84
85 me := &person{Name: "derek", Age: 22, Address: "140 New Montgomery St"}
86 me.Children = make(map[string]*person)
87
88 me.Children["sam"] = &person{Name: "sam", Age: 19, Address: "140 New Montgomery St"}
89 me.Children["meg"] = &person{Name: "meg", Age: 17, Address: "140 New Montgomery St"}
90
91 me.Assets = make(map[string]uint)
92 me.Assets["house"] = 1000
93 me.Assets["car"] = 100
94
95 ec.Subscribe("gob_struct", func(p *person) {
96 if !reflect.DeepEqual(p, me) {
97 t.Fatalf("Did not receive the correct struct response")
98 }
99 ch <- true
100 })
101
102 ec.Publish("gob_struct", me)
103 if e := Wait(ch); e != nil {
104 t.Fatal("Did not receive the message")
105 }
106}
107
108func BenchmarkPublishGobStruct(b *testing.B) {
109 // stop benchmark for set-up

Callers

nothing calls this directly

Calls 7

NewGobEncodedConnFunction · 0.85
FatalfMethod · 0.80
RunServerOnPortFunction · 0.70
WaitFunction · 0.70
SubscribeMethod · 0.65
PublishMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected