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

Function TestContextInvalid

test/context_test.go:792–821  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

790}
791
792func TestContextInvalid(t *testing.T) {
793 s := RunDefaultServer()
794 defer s.Shutdown()
795
796 nc := NewDefaultConnection(t)
797 defer nc.Close()
798
799 //lint:ignore SA1012 testing that passing nil fails
800 _, err := nc.RequestWithContext(nil, "foo", []byte(""))
801 if err == nil {
802 t.Fatal("Expected request to fail with error")
803 }
804 if err != nats.ErrInvalidContext {
805 t.Errorf("Expected request to fail with connection closed error: %s", err)
806 }
807
808 sub, err := nc.Subscribe("foo", func(_ *nats.Msg) {})
809 if err != nil {
810 t.Fatalf("Expected to be able to subscribe: %s", err)
811 }
812
813 //lint:ignore SA1012 testing that passing nil fails
814 _, err = sub.NextMsgWithContext(nil)
815 if err == nil {
816 t.Fatal("Expected request to fail with error")
817 }
818 if err != nats.ErrInvalidContext {
819 t.Errorf("Expected request to fail with connection closed error: %s", err)
820 }
821}

Callers

nothing calls this directly

Calls 8

ErrorfMethod · 0.80
FatalfMethod · 0.80
NextMsgWithContextMethod · 0.80
RunDefaultServerFunction · 0.70
NewDefaultConnectionFunction · 0.70
SubscribeMethod · 0.65
CloseMethod · 0.45
RequestWithContextMethod · 0.45

Tested by

no test coverage detected