(t *testing.T)
| 717 | } |
| 718 | |
| 719 | func TestRequestGOB(t *testing.T) { |
| 720 | ts := RunServerOnPort(ENC_TEST_PORT) |
| 721 | defer ts.Shutdown() |
| 722 | |
| 723 | type Request struct { |
| 724 | Name string |
| 725 | } |
| 726 | |
| 727 | type Person struct { |
| 728 | Name string |
| 729 | Age int |
| 730 | } |
| 731 | |
| 732 | nc, err := nats.Connect(options.Url) |
| 733 | if err != nil { |
| 734 | t.Fatalf("Could not connect: %v", err) |
| 735 | } |
| 736 | defer nc.Close() |
| 737 | |
| 738 | ec, err := nats.NewEncodedConn(nc, nats.GOB_ENCODER) |
| 739 | if err != nil { |
| 740 | t.Fatalf("Unable to create encoded connection: %v", err) |
| 741 | } |
| 742 | defer ec.Close() |
| 743 | |
| 744 | ec.QueueSubscribe("foo.request", "g", func(subject, reply string, r *Request) { |
| 745 | if r.Name != "meg" { |
| 746 | t.Fatalf("Expected request to be 'meg', got %q", r) |
| 747 | } |
| 748 | response := &Person{Name: "meg", Age: 21} |
| 749 | ec.Publish(reply, response) |
| 750 | }) |
| 751 | |
| 752 | reply := Person{} |
| 753 | if err := ec.Request("foo.request", &Request{Name: "meg"}, &reply, time.Second); err != nil { |
| 754 | t.Fatalf("Failed to receive response: %v", err) |
| 755 | } |
| 756 | if reply.Name != "meg" || reply.Age != 21 { |
| 757 | t.Fatalf("Did not receive proper response, %+v", reply) |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | func TestContextEncodedRequestWithTimeout(t *testing.T) { |
| 762 | s := RunDefaultServer() |
nothing calls this directly
no test coverage detected