Example #1
0
// GetClient gets an http.Client authenticated with the specified
// common.Credentials.
func GetClient(tripperFactory common.TripperFactory, creds *common.Credentials, provider common.Provider) (*http.Client, error) {

	tripper, tripperErr := tripperFactory.NewTripper(creds, provider)

	if tripperErr != nil {
		return nil, tripperErr
	}

	return &http.Client{Transport: tripper}, nil
}
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)

}