Example #1
0
func TestBindForm(t *testing.T) {
	is := is.New(t)
	testForm, _ := form.EncodeToString(TestStruct{1, "Ololo"})
	buf := bytes.NewBuffer([]byte(testForm))
	emptyBuf := bytes.NewBuffer([]byte("alskdjasdklj"))

	n := noodle.New(bind.Form(TestStruct{})).Then(bindHandlerFactory(is))
	r, _ := http.NewRequest("POST", "http://localhost", buf)
	is.NotErr(n(context.TODO(), httptest.NewRecorder(), r))

	r, _ = http.NewRequest("POST", "http://localhost", emptyBuf)
	is.Err(n(context.TODO(), httptest.NewRecorder(), r))
}
Example #2
0
// GetHTTPRequest which can be executed basing on given pull request data.
func (request *PullRequest) GetHTTPRequest(
	slave SecondaryServer,
) (*http.Request, error) {
	payload, err := form.EncodeToString(request)
	if err != nil {
		return nil, NewError(err, "can't create payload")
	}

	httpRequest, err := http.NewRequest(
		"POST", "http://"+string(slave)+"/", bytes.NewBufferString(payload),
	)
	if err != nil {
		return nil, err
	}

	httpRequest.Header.Set(
		"Content-Type", "application/x-www-form-urlencoded",
	)

	return httpRequest, nil
}