Пример #1
0
func TestHttpErrorPropagates(t *testing.T) {
	is := is.New(t)
	testError := errors.New("test error")

	n := noodle.New(noodleMW, adapt.Http(httpMW)).Then(
		func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
			return testError
		},
	)
	r, _ := http.NewRequest("GET", "http://localhost", nil)
	err := n(context.TODO(), httptest.NewRecorder(), r)
	is.Err(err)
	is.Equal(err, testError)
}
Пример #2
0
func TestHttpContextPasses(t *testing.T) {
	is := is.New(t)

	n := noodle.New(noodleMW, adapt.Http(httpMW)).Then(
		func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
			val, ok := ctx.Value("testKey").(string)
			is.True(ok)
			is.Equal(val, "testValue")
			return nil
		},
	)
	r, _ := http.NewRequest("GET", "http://localhost", nil)
	_ = n(context.TODO(), httptest.NewRecorder(), r)
}