func New(rw *ResponseWriter, req *protocol.Request) protocol.Protocol { return &dummyProtocol{ trans: memory.New([][]byte{}, [][]byte{}), req: req, rw: rw, } }
func TestSendRequestWithError(t *testing.T) { trans := memory.New( [][]byte{dummyRequest}, [][]byte{dummyResponseWithError}, ) proto := New(trans) req := protocol.Request{ "upper", protocol.Params{"text": "foobar"}, header.Header{}, } resp, err := proto.Send("", &req) if resp.Error != protocol.ServerError { t.Errorf("Error expected ServerError, else it was %s", err) } }
func TestReceiveRequest(t *testing.T) { trans := memory.New( [][]byte{dummyRequest}, [][]byte{dummyResponse}, ) proto := New(trans) _, req, _ := proto.Receive() if req.Method != "upper" { t.Errorf("Expected method %s, got %s", "upper", req.Method) } params := map[string]string{"text": "foobar"} if reflect.DeepEqual(req.Params, params) { t.Errorf("Expected params %s, got %s", params, req.Params) } }
func TestSendRequest(t *testing.T) { trans := memory.New( [][]byte{dummyRequest}, [][]byte{dummyResponse}, ) proto := New(trans) req := protocol.Request{ "upper", protocol.Params{"text": "foobar"}, header.Header{}, } resp, err := proto.Send("", &req) if err != nil { t.Errorf("Unexpected error: %v", err) } if resp.Body != "foobar" { t.Errorf("Expected response to be 'foobar', was %v", resp) } }