Exemple #1
0
func New(rw *ResponseWriter, req *protocol.Request) protocol.Protocol {
	return &dummyProtocol{
		trans: memory.New([][]byte{}, [][]byte{}),
		req:   req,
		rw:    rw,
	}
}
Exemple #2
0
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)
	}
}
Exemple #3
0
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)
	}
}
Exemple #4
0
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)
	}
}