当前位置: 首页>>代码示例>>Golang>>正文


Golang mock.AssertExpectationsForObjects函数代码示例

本文整理汇总了Golang中github.com/stretchr/testify/mock.AssertExpectationsForObjects函数的典型用法代码示例。如果您正苦于以下问题:Golang AssertExpectationsForObjects函数的具体用法?Golang AssertExpectationsForObjects怎么用?Golang AssertExpectationsForObjects使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了AssertExpectationsForObjects函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestMarshalWithCodec_WithFacade

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)

}
开发者ID:syohex,项目名称:codecs,代码行数:30,代码来源:web_codec_service_test.go

示例2: TestPublicData_WithArray

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")
	}

}
开发者ID:syohex,项目名称:codecs,代码行数:28,代码来源:facade_test.go

示例3: TestErrorHandlerGetsUsedOnError

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())

	}

}
开发者ID:anjijava16,项目名称:goweb,代码行数:35,代码来源:http_handler_test.go

示例4: TestMarshalWithCodec_WithError

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)

}
开发者ID:syohex,项目名称:codecs,代码行数:25,代码来源:web_codec_service_test.go

示例5: TestPipe_Handle

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)

}
开发者ID:antianlu,项目名称:goweb,代码行数:25,代码来源:pipe_test.go

示例6: TestMarshalWithCodec

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)

}
开发者ID:syohex,项目名称:codecs,代码行数:26,代码来源:web_codec_service_test.go

示例7: TestOAuth2Provider_Non200Response

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)

}
开发者ID:jmptrader,项目名称:gomniauth,代码行数:34,代码来源:complete_auth_test.go

示例8: TestNewUser

func TestNewUser(t *testing.T) {
	testProvider := new(test.TestProvider)
	testProvider.On("Name").Return("providerName")

	data := objx.MSI(
		spotifyKeyID, "123435467890",
		spotifyKeyName, "Mathew",
		spotifyKeyEmail, "[email protected]",
		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, "[email protected]", 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)
}
开发者ID:toggl,项目名称:gomniauth,代码行数:34,代码来源:user_test.go

示例9: TestProvider

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)

}
开发者ID:outrightmental,项目名称:go-omniauth,代码行数:27,代码来源:shortcuts_test.go

示例10: TestNewUser

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)

}
开发者ID:yamadapc,项目名称:gomniauth,代码行数:34,代码来源:user_test.go

示例11: TestPrependPreHandler

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)

}
开发者ID:anjijava16,项目名称:goweb,代码行数:26,代码来源:http_handler_test.go

示例12: TestRoundTrip

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)

}
开发者ID:amencarini,项目名称:gomniauth,代码行数:34,代码来源:oauth2_tripper_test.go

示例13: TestPublicData_WithError

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)

}
开发者ID:syohex,项目名称:codecs,代码行数:11,代码来源:facade_test.go

示例14: TestPublicDataMap_ReturningNil

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)

}
开发者ID:syohex,项目名称:codecs,代码行数:14,代码来源:facade_test.go

示例15: TestPublicData

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)

}
开发者ID:nelsam,项目名称:codecs,代码行数:14,代码来源:facade_test.go


注:本文中的github.com/stretchr/testify/mock.AssertExpectationsForObjects函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。