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

Function TestEncodedContextInvalid

test/enc_test.go:1079–1106  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1077}
1078
1079func TestEncodedContextInvalid(t *testing.T) {
1080 s := RunDefaultServer()
1081 defer s.Shutdown()
1082
1083 nc := NewDefaultConnection(t)
1084 c, err := nats.NewEncodedConn(nc, nats.JSON_ENCODER)
1085 if err != nil {
1086 t.Fatalf("Unable to create encoded connection: %v", err)
1087 }
1088 defer c.Close()
1089
1090 type request struct {
1091 Message string `json:"message"`
1092 }
1093 type response struct {
1094 Code int `json:"code"`
1095 }
1096 req := &request{Message: "Hello"}
1097 resp := &response{}
1098 //lint:ignore SA1012 testing that passing nil fails
1099 err = c.RequestWithContext(nil, "slow", req, resp)
1100 if err == nil {
1101 t.Fatal("Expected request to fail with error")
1102 }
1103 if err != nats.ErrInvalidContext {
1104 t.Errorf("Expected request to fail with invalid context: %s", err)
1105 }
1106}

Callers

nothing calls this directly

Calls 6

CloseMethod · 0.95
RequestWithContextMethod · 0.95
FatalfMethod · 0.80
ErrorfMethod · 0.80
RunDefaultServerFunction · 0.70
NewDefaultConnectionFunction · 0.70

Tested by

no test coverage detected