(t *testing.T)
| 472 | } |
| 473 | |
| 474 | func TestMsgRespond(t *testing.T) { |
| 475 | s := RunDefaultServer() |
| 476 | defer s.Shutdown() |
| 477 | nc := NewDefaultConnection(t) |
| 478 | defer nc.Close() |
| 479 | |
| 480 | m := &nats.Msg{} |
| 481 | if err := m.Respond(nil); err != nats.ErrMsgNotBound { |
| 482 | t.Fatal("Expected ErrMsgNotBound error") |
| 483 | } |
| 484 | |
| 485 | sub, err := nc.Subscribe("req", func(msg *nats.Msg) { |
| 486 | msg.Respond([]byte("42")) |
| 487 | }) |
| 488 | if err != nil { |
| 489 | t.Fatal("Failed to subscribe: ", err) |
| 490 | } |
| 491 | |
| 492 | // Fake the bound notion by assigning Sub directly to test no reply. |
| 493 | m.Sub = sub |
| 494 | if err := m.Respond(nil); err != nats.ErrMsgNoReply { |
| 495 | t.Fatal("Expected ErrMsgNoReply error") |
| 496 | } |
| 497 | |
| 498 | response, err := nc.Request("req", []byte("help"), 50*time.Millisecond) |
| 499 | if err != nil { |
| 500 | t.Fatal("Request Failed: ", err) |
| 501 | } |
| 502 | |
| 503 | if string(response.Data) != "42" { |
| 504 | t.Fatalf("Expected '42', got %q", response.Data) |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | func TestFlush(t *testing.T) { |
| 509 | s := RunDefaultServer() |
nothing calls this directly
no test coverage detected