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

Function TestBadSubjectsAndQueueNames

test/nats_test.go:637–662  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

635}
636
637func TestBadSubjectsAndQueueNames(t *testing.T) {
638 s := RunServerOnPort(TEST_PORT)
639 defer s.Shutdown()
640
641 nc, err := nats.Connect(fmt.Sprintf("127.0.0.1:%d", TEST_PORT))
642 if err != nil {
643 t.Fatalf("Error connecting: %v", err)
644 }
645 defer nc.Close()
646
647 // Make sure we get errors on bad subjects (spaces, etc)
648 // We want the client to protect the user.
649 badSubs := []string{"foo bar", "foo..bar", ".foo", "bar.baz.", "baz\t.foo"}
650 for _, subj := range badSubs {
651 if _, err := nc.SubscribeSync(subj); err != nats.ErrBadSubject {
652 t.Fatalf("Expected an error of ErrBadSubject for %q, got %v", subj, err)
653 }
654 }
655
656 badQueues := []string{"foo group", "group\t1", "g1\r\n2"}
657 for _, q := range badQueues {
658 if _, err := nc.QueueSubscribeSync("foo", q); err != nats.ErrBadQueueName {
659 t.Fatalf("Expected an error of ErrBadQueueName for %q, got %v", q, err)
660 }
661 }
662}
663
664func TestTypeSubscription(t *testing.T) {
665 s := RunServerOnPort(TEST_PORT)

Callers

nothing calls this directly

Calls 6

ConnectMethod · 0.80
FatalfMethod · 0.80
RunServerOnPortFunction · 0.70
SubscribeSyncMethod · 0.65
QueueSubscribeSyncMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected