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

Function TestBasicHeaders

test/headers_test.go:33–64  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

31)
32
33func TestBasicHeaders(t *testing.T) {
34 s := RunServerOnPort(-1)
35 defer s.Shutdown()
36
37 nc, err := nats.Connect(s.ClientURL())
38 if err != nil {
39 t.Fatalf("Error connecting to server: %v", err)
40 }
41 defer nc.Close()
42
43 subject := "headers.test"
44 sub, err := nc.SubscribeSync(subject)
45 if err != nil {
46 t.Fatalf("Could not subscribe to %q: %v", subject, err)
47 }
48 defer sub.Unsubscribe()
49
50 m := nats.NewMsg(subject)
51 m.Header.Add("Accept-Encoding", "json")
52 m.Header.Add("Authorization", "s3cr3t")
53 m.Data = []byte("Hello Headers!")
54
55 nc.PublishMsg(m)
56 msg, err := sub.NextMsg(time.Second)
57 if err != nil {
58 t.Fatalf("Did not receive response: %v", err)
59 }
60
61 if !m.Equal(msg) {
62 t.Fatalf("Messages did not match! \n%+v\n%+v\n", m, msg)
63 }
64}
65
66func TestRequestMsg(t *testing.T) {
67 s := RunServerOnPort(-1)

Callers

nothing calls this directly

Calls 10

EqualMethod · 0.95
ConnectMethod · 0.80
FatalfMethod · 0.80
UnsubscribeMethod · 0.80
NextMsgMethod · 0.80
RunServerOnPortFunction · 0.70
SubscribeSyncMethod · 0.65
AddMethod · 0.65
PublishMsgMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected