Пример #1
0
func TestMarshalWithCodec_WithFacade(t *testing.T) {

	// func (s *WebCodecService) MarshalWithCodec(codec codecs.Codec, object interface{}, options ...interface{}) ([]byte, error) {

	testCodec := new(test.TestCodec)
	service := NewWebCodecService()

	// make some test stuff
	var bytesToReturn []byte = []byte("Hello World")
	testObjectWithFacade := new(test.TestObjectWithFacade)
	object := objx.MSI("Name", "Mat")
	var option1 string = "Option One"
	var option2 string = "Option Two"

	args := map[string]interface{}{option1: option1, option2: option2}

	// setup expectations
	testObjectWithFacade.On("PublicData", args).Return(object, nil)
	testCodec.On("Marshal", object, args).Return(bytesToReturn, nil)

	bytes, err := service.MarshalWithCodec(testCodec, testObjectWithFacade, args)

	if assert.Nil(t, err) {
		assert.Equal(t, string(bytesToReturn), string(bytes))
	}

	// assert that our expectations were met
	mock.AssertExpectationsForObjects(t, testCodec.Mock, testObjectWithFacade.Mock)

}
Пример #2
0
func TestPublicData_WithArray(t *testing.T) {

	o := new(test.TestObjectWithFacade)
	o1 := new(test.TestObjectWithFacade)
	o2 := new(test.TestObjectWithFacade)

	arr := []interface{}{o, o1, o2}

	o.Mock.On("PublicData", map[string]interface{}{}).Return(objx.New(map[string]interface{}{"theName": "1"}), nil)
	o1.Mock.On("PublicData", map[string]interface{}{}).Return(objx.New(map[string]interface{}{"theName": "2"}), nil)
	o2.Mock.On("PublicData", map[string]interface{}{}).Return(objx.New(map[string]interface{}{"theName": "3"}), nil)

	public, err := PublicData(arr, map[string]interface{}{})

	if assert.Nil(t, err) {
		assert.Equal(t, reflect.Slice, reflect.TypeOf(public).Kind(), "Result should be array not %v", reflect.TypeOf(public))
	}

	mock.AssertExpectationsForObjects(t, o.Mock, o1.Mock, o2.Mock)

	publicArray := public.([]interface{})
	if assert.Equal(t, 3, len(publicArray)) {
		assert.Equal(t, publicArray[0].(objx.Map).Get("theName").Str(), "1", "o")
		assert.Equal(t, publicArray[1].(objx.Map).Get("theName").Str(), "2", "o1")
		assert.Equal(t, publicArray[2].(objx.Map).Get("theName").Str(), "3", "o2")
	}

}
Пример #3
0
func TestErrorHandlerGetsUsedOnError(t *testing.T) {

	responseWriter := new(http_test.TestResponseWriter)
	testRequest, _ := http.NewRequest("GET", "http://stretchr.org/goweb", nil)

	codecService := codecsservices.NewWebCodecService()
	handler := NewHttpHandler(codecService)

	errorHandler := new(handlers_test.TestHandler)
	handler.SetErrorHandler(errorHandler)

	errorHandler.On("Handle", mock.Anything).Return(false, nil)

	// make a handler throw an error
	var theError error = errors.New("Test error")
	handler.Map(func(c context.Context) error {
		return theError
	})

	handler.ServeHTTP(responseWriter, testRequest)

	if mock.AssertExpectationsForObjects(t, errorHandler.Mock) {

		// get the first context
		ctx := errorHandler.Calls[0].Arguments[0].(context.Context)

		// make sure the error data field was set
		assert.Equal(t, theError.Error(), ctx.Data().Get("error").Data().(HandlerError).Error(), "the error should be set in the data with the 'error' key")

		assert.Equal(t, responseWriter, ctx.HttpResponseWriter())
		assert.Equal(t, testRequest, ctx.HttpRequest())

	}

}
Пример #4
0
func TestMarshalWithCodec_WithError(t *testing.T) {

	// func (s *WebCodecService) MarshalWithCodec(codec codecs.Codec, object interface{}, options ...interface{}) ([]byte, error) {

	testCodec := new(test.TestCodec)
	service := NewWebCodecService()

	// make some test stuff
	object := objx.MSI("Name", "Mat")
	var option1 string = "Option One"
	var option2 string = "Option Two"

	args := map[string]interface{}{option1: option1, option2: option2}

	// setup expectations
	testCodec.On("Marshal", object, args).Return(nil, assert.AnError)

	_, err := service.MarshalWithCodec(testCodec, object, args)

	assert.Equal(t, assert.AnError, err, "The error should get returned")

	// assert that our expectations were met
	mock.AssertExpectationsForObjects(t, testCodec.Mock)

}
Пример #5
0
func TestPipe_Handle(t *testing.T) {

	ctx := context_test.MakeTestContext()

	handler1 := new(handlers_test.TestHandler)
	handler2 := new(handlers_test.TestHandler)
	handler3 := new(handlers_test.TestHandler)

	// add the handlers to the pipe
	p := Pipe{handler1, handler2, handler3}

	// setup expectations
	handler1.On("WillHandle", ctx).Return(true, nil)
	handler1.On("Handle", ctx).Return(false, nil)
	handler2.On("WillHandle", ctx).Return(false, nil)
	handler3.On("WillHandle", ctx).Return(true, nil)
	handler3.On("Handle", ctx).Return(false, nil)

	// call handle
	p.Handle(ctx)

	// assert expectations
	mock.AssertExpectationsForObjects(t, handler1.Mock, handler2.Mock, handler3.Mock)

}
Пример #6
0
func TestMarshalWithCodec(t *testing.T) {

	testCodec := new(test.TestCodec)
	service := NewWebCodecService()

	// make some test stuff
	var bytesToReturn []byte = []byte("Hello World")
	var object objx.Map = objx.MSI("Name", "Mat")
	var option1 string = "Option One"
	var option2 string = "Option Two"

	args := map[string]interface{}{option1: option1, option2: option2}

	// setup expectations
	testCodec.On("Marshal", object, args).Return(bytesToReturn, nil)

	bytes, err := service.MarshalWithCodec(testCodec, object, args)

	if assert.Nil(t, err) {
		assert.Equal(t, string(bytesToReturn), string(bytes))
	}

	// assert that our expectations were met
	mock.AssertExpectationsForObjects(t, testCodec.Mock)

}
Пример #7
0
func TestOAuth2Provider_Non200Response(t *testing.T) {

	config := &common.Config{
		Map: objx.MSI(
			OAuth2KeyRedirectUrl, OAuth2KeyRedirectUrl,
			OAuth2KeyScope, OAuth2KeyScope,
			OAuth2KeyClientID, OAuth2KeyClientID,
			OAuth2KeySecret, OAuth2KeySecret,
			OAuth2KeyAuthURL, OAuth2KeyAuthURL,
			OAuth2KeyTokenURL, OAuth2KeyTokenURL)}

	testTripperFactory := new(test.TestTripperFactory)
	testTripper := new(test.TestTripper)
	testProvider := new(test.TestProvider)

	testResponse := new(http.Response)
	testResponse.Header = make(http.Header)
	testResponse.Header.Set("Content-Type", "text/plain")
	testResponse.StatusCode = 401
	testResponse.Body = ioutil.NopCloser(strings.NewReader("No mate"))

	testTripperFactory.On("NewTripper", common.EmptyCredentials, mock.Anything).Return(testTripper, nil)
	testTripper.On("RoundTrip", mock.Anything).Return(testResponse, nil)

	data := objx.MSI(OAuth2KeyCode, []string{"123"})
	_, err := CompleteAuth(testTripperFactory, data, config, testProvider)

	if assert.Error(t, err) {
		assert.IsType(t, &common.AuthServerError{}, err)
	}

	mock.AssertExpectationsForObjects(t, testTripperFactory.Mock, testTripper.Mock, testProvider.Mock)

}
Пример #8
0
func TestNewUser(t *testing.T) {
	testProvider := new(test.TestProvider)
	testProvider.On("Name").Return("providerName")

	data := objx.MSI(
		spotifyKeyID, "123435467890",
		spotifyKeyName, "Mathew",
		spotifyKeyEmail, "*****@*****.**",
		spotifyKeyNickname, "Mat",
	)

	creds := &common.Credentials{Map: objx.MSI(oauth2.OAuth2KeyAccessToken, "ABC123")}

	user := NewUser(data, creds, testProvider)

	if assert.NotNil(t, user) {

		assert.Equal(t, data, user.Data())

		assert.Equal(t, "Mathew", user.Name())
		assert.Equal(t, "*****@*****.**", user.Email())
		assert.Equal(t, "Mat", user.Nickname())

		// check provider credentials
		creds := user.ProviderCredentials()[testProvider.Name()]
		if assert.NotNil(t, creds) {
			assert.Equal(t, "ABC123", creds.Get(oauth2.OAuth2KeyAccessToken).Str())
			assert.Equal(t, "123435467890", creds.Get(common.CredentialsKeyID).Str())
		}

	}

	mock.AssertExpectationsForObjects(t, testProvider.Mock)
}
Пример #9
0
func TestProvider(t *testing.T) {

	prov1 := new(test.TestProvider)
	prov2 := new(test.TestProvider)

	prov1.On("Name").Return("prov1")
	prov2.On("Name").Return("prov2")

	// build a list
	list := WithProviders(prov1, prov2)

	returnedProv, err := list.Provider("prov1")

	if assert.NoError(t, err) {
		assert.Equal(t, returnedProv, prov1)
	}

	// check nonsense name
	returnedProv, err = Provider("no such provider")

	if assert.Nil(t, returnedProv) {
		assert.IsType(t, &common.MissingProviderError{}, err, "MissingProviderError expected")
	}

	mock.AssertExpectationsForObjects(t, prov1.Mock, prov2.Mock)

}
Пример #10
0
func TestNewUser(t *testing.T) {

	testProvider := new(test.TestProvider)
	testProvider.On("Name").Return("providerName")

	data := objx.MSI(
		instagramKeyID, "123435467890",
		instagramKeyName, "Raquel",
		instagramKeyNickname, "maggit",
		instagramKeyAvatarUrl, "http://instagram.com/")
	creds := &common.Credentials{Map: objx.MSI(oauth2.OAuth2KeyAccessToken, "ABC12345")}

	user := NewUser(data, creds, testProvider)

	if assert.NotNil(t, user) {

		assert.Equal(t, data, user.Data())

		assert.Equal(t, "Raquel", user.Name())
		assert.Equal(t, "maggit", user.Nickname())
		assert.Equal(t, "http://instagram.com/", user.AvatarURL())

		// check provider credentials
		creds := user.ProviderCredentials()[testProvider.Name()]
		if assert.NotNil(t, creds) {
			assert.Equal(t, "ABC12345", creds.Get(oauth2.OAuth2KeyAccessToken).Str())
			assert.Equal(t, "123435467890", creds.Get(common.CredentialsKeyID).Str())
		}

	}

	mock.AssertExpectationsForObjects(t, testProvider.Mock)

}
Пример #11
0
func TestPrependPreHandler(t *testing.T) {

	handler1 := new(handlers_test.TestHandler)
	handler2 := new(handlers_test.TestHandler)
	codecService := codecsservices.NewWebCodecService()
	h := NewHttpHandler(codecService)

	handler1.TestData().Set("id", 1)
	handler2.TestData().Set("id", 2)

	handler1.On("WillHandle", mock.Anything).Return(true, nil)
	handler1.On("Handle", mock.Anything).Return(false, nil)
	handler2.On("WillHandle", mock.Anything).Return(true, nil)
	handler2.On("Handle", mock.Anything).Return(false, nil)

	h.PrependPreHandler(handler1)
	h.PrependPreHandler(handler2)
	h.Handlers.Handle(nil)
	assert.Equal(t, 2, len(h.PreHandlersPipe()))

	assert.Equal(t, 2, h.PreHandlersPipe()[0].(*handlers_test.TestHandler).TestData().Get("id").Data())
	assert.Equal(t, 1, h.PreHandlersPipe()[1].(*handlers_test.TestHandler).TestData().Get("id").Data())

	mock.AssertExpectationsForObjects(t, handler1.Mock)

}
Пример #12
0
func TestRoundTrip(t *testing.T) {

	underlyingTripper := new(testifyhttp.TestRoundTripper)
	testProvider := new(test.TestProvider)
	creds := &common.Credentials{Map: objx.MSI()}
	creds.Set(OAuth2KeyAccessToken, "This is a real access token :)")

	tripper := new(OAuth2Tripper)
	tripper.underlyingTransport = underlyingTripper
	tripper.credentials = creds
	tripper.provider = testProvider

	request, _ := http.NewRequest("GET", "something", nil)

	underlyingTripper.On("RoundTrip", mock.Anything).Return(new(http.Response), nil)

	response, err := tripper.RoundTrip(request)

	if assert.NoError(t, err) {
		if assert.NotNil(t, response) {

			actualRequest := underlyingTripper.Calls[0].Arguments[0].(*http.Request)

			if assert.NotEqual(t, &actualRequest, &request, "Actual request should be different") {
				headerK, headerV := AuthorizationHeader(creds)
				assert.Equal(t, actualRequest.Header.Get(headerK), headerV)
			}

		}
	}

	mock.AssertExpectationsForObjects(t, testProvider.Mock, underlyingTripper.Mock)

}
Пример #13
0
func TestPublicData_WithError(t *testing.T) {

	o := new(test.TestObjectWithFacade)
	o.Mock.On("PublicData", map[string]interface{}{}).Return(nil, assert.AnError)

	_, err := PublicData(o, map[string]interface{}{})

	assert.Equal(t, assert.AnError, err)
	mock.AssertExpectationsForObjects(t, o.Mock)

}
Пример #14
0
func TestPublicDataMap_ReturningNil(t *testing.T) {

	o := new(test.TestObjectWithFacade)
	o.Mock.On("PublicData", map[string]interface{}{}).Return(nil, nil)

	public, err := PublicDataMap(o, map[string]interface{}{})

	if assert.Nil(t, err) {
		assert.Nil(t, public)
	}

	mock.AssertExpectationsForObjects(t, o.Mock)

}
Пример #15
0
func TestPublicData(t *testing.T) {

	o := new(test.TestObjectWithFacade)
	o.Mock.On("PublicData", map[string]interface{}{}).Return(objects.Map{"theName": "Mat"}, nil)

	public, err := PublicData(o, map[string]interface{}{})

	if assert.Nil(t, err) {
		assert.Equal(t, public.(objects.Map)["theName"], "Mat")
	}

	mock.AssertExpectationsForObjects(t, o.Mock)

}
Пример #16
0
func TestPublicDataMap_WithMSI(t *testing.T) {

	o := new(test.TestObjectWithFacade)
	o.Mock.On("PublicData", map[string]interface{}{}).Return(map[string]interface{}{"theName": "Mat"}, nil)

	public, err := PublicDataMap(o, map[string]interface{}{})

	if assert.Nil(t, err) {
		assert.Equal(t, public.Get("theName").Str(), "Mat")
	}

	mock.AssertExpectationsForObjects(t, o.Mock)

}
Пример #17
0
func TestAppendPostHandler(t *testing.T) {

	handler1 := new(handlers_test.TestHandler)
	codecService := codecsservices.NewWebCodecService()
	h := NewHttpHandler(codecService)

	handler1.On("WillHandle", mock.Anything).Return(true, nil)
	handler1.On("Handle", mock.Anything).Return(false, nil)

	h.AppendPostHandler(handler1)
	h.Handlers.Handle(nil)
	assert.Equal(t, 1, len(h.PostHandlersPipe()))

	mock.AssertExpectationsForObjects(t, handler1.Mock)

}
Пример #18
0
func TestPublicData_WithRecursion(t *testing.T) {

	o := new(test.TestObjectWithFacade)
	o1 := new(test.TestObjectWithFacade)
	o2 := new(test.TestObjectWithFacade)

	o.Mock.On("PublicData", map[string]interface{}{}).Return(o1, nil)
	o1.Mock.On("PublicData", map[string]interface{}{}).Return(o2, nil)
	o2.Mock.On("PublicData", map[string]interface{}{}).Return(objx.New(map[string]interface{}{"theName": "Mat"}), nil)

	public, err := PublicData(o, map[string]interface{}{})

	if assert.Nil(t, err) {
		assert.Equal(t, public.(objx.Map).Get("theName").Str(), "Mat")
	}

	mock.AssertExpectationsForObjects(t, o.Mock, o1.Mock, o2.Mock)

}
Пример #19
0
func TestServeHTTPMethodOverride(t *testing.T) {

	responseWriter := new(http_test.TestResponseWriter)
	testRequest, _ := http.NewRequest("POST", "http://stretchr.org/goweb", nil)
	testRequest.Header.Set("X-HTTP-Method-Override", "GET")
	codecService := codecsservices.NewWebCodecService()
	handler := NewHttpHandler(codecService)

	// setup some test handlers
	handler1 := new(handlers_test.TestHandler)
	handler2 := new(handlers_test.TestHandler)
	handler3 := new(handlers_test.TestHandler)

	handler.Handlers = append(handler.Handlers, handler1)
	handler.Handlers = append(handler.Handlers, handler2)
	handler.Handlers = append(handler.Handlers, handler3)

	handler1.On("WillHandle", mock.Anything).Return(true, nil)
	handler1.On("Handle", mock.Anything).Return(false, nil)
	handler2.On("WillHandle", mock.Anything).Return(true, nil)
	handler2.On("Handle", mock.Anything).Return(false, nil)
	handler3.On("WillHandle", mock.Anything).Return(true, nil)
	handler3.On("Handle", mock.Anything).Return(false, nil)

	handler.ServeHTTP(responseWriter, testRequest)

	mock.AssertExpectationsForObjects(t, handler1.Mock, handler2.Mock, handler3.Mock)

	// get the first context
	ctx := handler1.Calls[0].Arguments[0].(context.Context)

	assert.Equal(t, responseWriter, ctx.HttpResponseWriter())
	assert.Equal(t, testRequest, ctx.HttpRequest())

	// make sure it's always the same context
	ctx1 := handler1.Calls[0].Arguments[0].(context.Context)
	ctx2 := handler2.Calls[0].Arguments[0].(context.Context)
	ctx3 := handler3.Calls[0].Arguments[0].(context.Context)

	assert.Equal(t, ctx1, ctx2, "Contexts should be the same")
	assert.Equal(t, ctx2, ctx3, "Contexts should be the same")

}
Пример #20
0
func TestBeforeAndAfterHandlers(t *testing.T) {

	responseWriter := new(http_test.TestResponseWriter)
	testRequest, _ := http.NewRequest("GET", "http://stretchr.org/goweb", nil)
	codecService := codecsservices.NewWebCodecService()
	handler := NewHttpHandler(codecService)

	// setup some test handlers
	handler1 := new(handlers_test.TestHandler)
	handler2 := new(handlers_test.TestHandler)
	handler3 := new(handlers_test.TestHandler)

	handler.MapBefore(func(c context.Context) error {
		_, err := handler1.Handle(c)
		return err
	})
	handler.Map(func(c context.Context) error {
		_, err := handler2.Handle(c)
		return err
	})
	handler.MapAfter(func(c context.Context) error {
		_, err := handler3.Handle(c)
		return err
	})

	handler1.On("Handle", mock.Anything).Return(false, nil)
	handler2.On("Handle", mock.Anything).Return(false, nil)
	handler3.On("Handle", mock.Anything).Return(false, nil)

	handler.ServeHTTP(responseWriter, testRequest)

	mock.AssertExpectationsForObjects(t, handler1.Mock, handler2.Mock, handler3.Mock)

	// make sure it's always the same context
	ctx1 := handler1.Calls[0].Arguments[0].(context.Context)
	ctx2 := handler2.Calls[0].Arguments[0].(context.Context)
	ctx3 := handler3.Calls[0].Arguments[0].(context.Context)

	assert.Equal(t, ctx1, ctx2, "Contexts should be the same")
	assert.Equal(t, ctx2, ctx3, "Contexts should be the same")

}
Пример #21
0
func TestOAuth2Provider_CompleteAuth_JSON(t *testing.T) {

	config := &common.Config{
		Map: objx.MSI(
			OAuth2KeyRedirectUrl, OAuth2KeyRedirectUrl,
			OAuth2KeyScope, OAuth2KeyScope,
			OAuth2KeyClientID, OAuth2KeyClientID,
			OAuth2KeySecret, OAuth2KeySecret,
			OAuth2KeyAuthURL, OAuth2KeyAuthURL,
			OAuth2KeyTokenURL, OAuth2KeyTokenURL)}

	testTripperFactory := new(test.TestTripperFactory)
	testTripper := new(test.TestTripper)
	testProvider := new(test.TestProvider)

	creds := new(common.Credentials)

	testResponse := new(http.Response)
	testResponse.Header = make(http.Header)
	testResponse.Header.Set("Content-Type", "application/json")
	testResponse.StatusCode = 200
	testResponse.Body = ioutil.NopCloser(strings.NewReader(`{"expires_in":20,"access_token":"ACCESSTOKEN","refresh_token":"REFRESHTOKEN"}`))

	testTripperFactory.On("NewTripper", common.EmptyCredentials, mock.Anything).Return(testTripper, nil)
	testTripper.On("RoundTrip", mock.Anything).Return(testResponse, nil)

	data := objx.MSI(OAuth2KeyCode, []string{"123"})
	creds, err := CompleteAuth(testTripperFactory, data, config, testProvider)

	if assert.NoError(t, err) {
		if assert.NotNil(t, creds, "Creds should be returned") {

			assert.Equal(t, creds.Get(OAuth2KeyAccessToken).Str(), "ACCESSTOKEN")
			assert.Equal(t, creds.Get(OAuth2KeyRefreshToken).Str(), "REFRESHTOKEN")
			assert.Equal(t, creds.Get(OAuth2KeyExpiresIn).Data().(time.Duration), 20000000000)

		}
	}

	mock.AssertExpectationsForObjects(t, testTripperFactory.Mock, testTripper.Mock, testProvider.Mock)

}
Пример #22
0
func TestUnmarshalWithCodec_WithError(t *testing.T) {

	// func (s *WebCodecService) UnmarshalWithCodec(codec codecs.Codec, data []byte, object interface{}) error {

	testCodec := new(test.TestCodec)
	service := NewWebCodecService()

	// some test objects
	object := struct{}{}
	data := []byte("Some bytes")

	// setup expectations
	testCodec.On("Unmarshal", data, object).Return(assert.AnError)

	// call the target method
	err := service.UnmarshalWithCodec(testCodec, data, object)

	assert.Equal(t, assert.AnError, err)
	mock.AssertExpectationsForObjects(t, testCodec.Mock)

}
Пример #23
0
func TestPublicData_WithRecursion_WithObjects(t *testing.T) {

	o := new(test.TestObjectWithFacade)
	o1 := new(test.TestObjectWithFacade)
	o2 := new(test.TestObjectWithFacade)

	args := map[string]interface{}{constants.OptionKeyClientCallback: "~d"}

	o.Mock.On("PublicData", args).Return(o1, nil)
	o1.Mock.On("PublicData", args).Return(o2, nil)
	o2.Mock.On("PublicData", args).Return(objx.New(map[string]interface{}{"theName": "Mat"}), nil)

	public, err := PublicData(o, args)

	if assert.Nil(t, err) {
		assert.Equal(t, public.(objx.Map).Get("theName").Str(), "Mat")
	}

	mock.AssertExpectationsForObjects(t, o.Mock, o1.Mock, o2.Mock)

}
Пример #24
0
func TestOAuth2ProviderGetClient(t *testing.T) {

	testTripperFactory := new(test.TestTripperFactory)
	testTripper := new(test.TestTripper)
	testProvider := new(test.TestProvider)

	creds := new(common.Credentials)

	testTripperFactory.On("NewTripper", creds, mock.Anything).Return(testTripper, nil)

	client, clientErr := GetClient(testTripperFactory, creds, testProvider)

	if assert.NoError(t, clientErr) {
		if assert.NotNil(t, client) {
			assert.Equal(t, client.Transport, testTripper)
		}
	}

	mock.AssertExpectationsForObjects(t, testTripperFactory.Mock, testTripper.Mock, testProvider.Mock)

}
func TestOAuth2TripperFactoryNewTripper(t *testing.T) {

	testProvider := new(test.TestProvider)

	creds := new(common.Credentials)
	var tripperFactory common.TripperFactory
	tripperFactory = new(OAuth2TripperFactory)

	assert.NotNil(t, tripperFactory)

	var tripper common.Tripper
	tripper, err := tripperFactory.NewTripper(creds, testProvider)

	if assert.NotNil(t, tripper) && assert.NoError(t, err) {

		assert.Equal(t, creds, tripper.Credentials())
		assert.IsType(t, new(OAuth2Tripper), tripper, "OAuth2TripperFactory should make OAuth2Trippers")

	}

	mock.AssertExpectationsForObjects(t, testProvider.Mock)

}
Пример #26
0
func TestDataGetsCopiedToEachContext(t *testing.T) {

	codecService := codecsservices.NewWebCodecService()
	handler1 := new(handlers_test.TestHandler)
	h := NewHttpHandler(codecService)

	h.Data.Set("name", "Mat")

	handler1.On("WillHandle", mock.Anything).Return(true, nil)
	handler1.On("Handle", mock.Anything).Return(false, nil)

	h.AppendHandler(handler1)
	req, _ := http.NewRequest("GET", "something", nil)
	h.ServeHTTP(nil, req)

	assert.Equal(t, 1, len(h.HandlersPipe()))

	mock.AssertExpectationsForObjects(t, handler1.Mock)
	ctx := handler1.Calls[0].Arguments[0].(context.Context)

	assert.Equal(t, ctx.Data().Get("name").Str(), "Mat")

}