本文整理汇总了Golang中github.com/stretchr/gomniauth/test.TestProvider类的典型用法代码示例。如果您正苦于以下问题:Golang TestProvider类的具体用法?Golang TestProvider怎么用?Golang TestProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestProvider类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestGetUser
func TestGetUser(t *testing.T) {
testProvider := new(test.TestProvider)
creds := new(common.Credentials)
testTripperFactory := new(test.TestTripperFactory)
testTripper := new(test.TestTripper)
testTripperFactory.On("NewTripper", creds, testProvider).Return(testTripper, nil)
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(`{"name":"their-name","id":"uniqueid","login":"loginname","email":"[email protected]","avatar_url":"http://myface.com/","blog":"http://blog.com/"}`))
testTripper.On("RoundTrip", mock.Anything).Return(testResponse, nil)
client := &http.Client{Transport: testTripper}
testProvider.On("GetClient", creds).Return(client, nil)
data, err := Get(testProvider, creds, "endpoint")
if assert.NoError(t, err) && assert.NotNil(t, data) {
assert.Equal(t, data["name"], "their-name")
assert.Equal(t, data["id"], "uniqueid")
assert.Equal(t, data["login"], "loginname")
assert.Equal(t, data["email"], "[email protected]")
assert.Equal(t, data["avatar_url"], "http://myface.com/")
assert.Equal(t, data["blog"], "http://blog.com/")
}
}
开发者ID:amencarini,项目名称:gomniauth,代码行数:32,代码来源:get_test.go
示例2: TestNewUser
func TestNewUser(t *testing.T) {
testProvider := new(test.TestProvider)
testProvider.On("Name").Return("providerName")
data := objx.MSI(
herokuKeyID, "123435467890",
herokuKeyEmail, "[email protected]")
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, "[email protected]", user.Email())
// 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:amencarini,项目名称:gomniauth,代码行数:30,代码来源:user_test.go
示例3: 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
示例4: TestProviderPublicData
func TestProviderPublicData(t *testing.T) {
provider := new(test.TestProvider)
provider.On("Name").Return("TestName")
provider.On("DisplayName").Return("TestDisplayName")
publicData, _ := ProviderPublicData(provider, objx.MSI("loginpathFormat", "~auth/%s/login"))
publicDataMap := publicData.(map[string]interface{})
assert.Equal(t, publicDataMap["name"], "TestName")
assert.Equal(t, publicDataMap["display"], "TestDisplayName")
assert.Equal(t, publicDataMap["loginpath"], "~auth/TestName/login")
}
开发者ID:amencarini,项目名称:gomniauth,代码行数:15,代码来源:facade_test.go
示例5: TestProviderListProvider
func TestProviderListProvider(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 = list.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:amencarini,项目名称:gomniauth,代码行数:27,代码来源:provider_list_test.go
注:本文中的github.com/stretchr/gomniauth/test.TestProvider类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论