本文整理汇总了Golang中github.com/chikin14niwa/gomniauth/test.TestProvider类的典型用法代码示例。如果您正苦于以下问题:Golang TestProvider类的具体用法?Golang TestProvider怎么用?Golang TestProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestProvider类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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/")
}
}
示例2: TestNewUser
func TestNewUser(t *testing.T) {
testProvider := new(test.TestProvider)
testProvider.On("Name").Return("providerName")
data := objx.MSI(
soundcloudKeyID, "123435467890",
soundcloudKeyName, "Mathew",
soundcloudKeyNickname, "mathew_testington",
soundcloudKeyAvatarUrl, "http://myface.com/")
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, "mathew_testington", user.Nickname())
assert.Equal(t, "http://myface.com/", user.AvatarURL())
// 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)
}
示例3: 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")
}
示例4: 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)
}