本文整理匯總了Golang中github.com/RichardKnop/example-api/accounts.User.GetName方法的典型用法代碼示例。如果您正苦於以下問題:Golang User.GetName方法的具體用法?Golang User.GetName怎麽用?Golang User.GetName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/RichardKnop/example-api/accounts.User
的用法示例。
在下文中一共展示了User.GetName方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestUserGetName
func TestUserGetName(t *testing.T) {
user := new(accounts.User)
assert.Equal(t, "", user.GetName())
user.FirstName = util.StringOrNull("John")
user.LastName = util.StringOrNull("Reese")
assert.Equal(t, "John Reese", user.GetName())
}
示例2: TestLoginExistingUser
func (suite *FacebookTestSuite) TestLoginExistingUser() {
var (
testOauthUser *oauth.User
testUser *accounts.User
err error
)
// Insert a test user
testOauthUser, err = suite.service.GetAccountsService().GetOauthService().CreateUser(
roles.User,
"[email protected]",
"", // empty password
)
assert.NoError(suite.T(), err, "Failed to insert a test oauth user")
testUser, err = accounts.NewUser(
suite.accounts[0],
testOauthUser,
"some_facebook_id", // facebook ID
true, // confirmed
&accounts.UserRequest{
FirstName: "Harold",
LastName: "Finch",
Picture: "some_picture",
},
)
assert.NoError(suite.T(), err, "Failed to create a new test account user object")
err = suite.db.Create(testUser).Error
assert.NoError(suite.T(), err, "Failed to insert a test user")
testUser.OauthUser = testOauthUser
// Prepare a request
r, err := http.NewRequest("POST", "http://1.2.3.4/v1/facebook/login", nil)
assert.NoError(suite.T(), err, "Request setup should not get an error")
r.PostForm = url.Values{
"access_token": {"facebook_token"},
"scope": {"read_write"},
}
r.SetBasicAuth("test_client_1", "test_secret")
// Check the routing
match := new(mux.RouteMatch)
suite.router.Match(r, match)
if assert.NotNil(suite.T(), match.Route) {
assert.Equal(suite.T(), "facebook_login", match.Route.GetName())
}
// Mock fetching profile data from facebook
suite.mockFacebookGetMe(fb.Result{
"id": "some_facebook_id",
"email": testUser.OauthUser.Username,
"name": testUser.GetName(),
"first_name": testUser.FirstName.String,
"last_name": testUser.LastName.String,
"picture": map[string]interface{}{
"data": map[string]interface{}{
"url": testUser.Picture.String,
},
},
}, nil)
// Count before
var countBefore int
suite.db.Model(new(accounts.User)).Count(&countBefore)
// And serve the request
w := httptest.NewRecorder()
suite.router.ServeHTTP(w, r)
// Check mock expectations were met
suite.adapterMock.AssertExpectations(suite.T())
// Check the status code
if !assert.Equal(suite.T(), 200, w.Code) {
log.Print(w.Body.String())
}
// Count after
var countAfter int
suite.db.Model(new(accounts.User)).Count(&countAfter)
assert.Equal(suite.T(), countBefore, countAfter)
// Fetch the logged in user
user := new(accounts.User)
notFound := accounts.UserPreload(suite.db).
First(user, testUser.ID).RecordNotFound()
assert.False(suite.T(), notFound)
// The user should not have changed
assert.Equal(suite.T(), testUser.OauthUser.Username, user.OauthUser.Username)
assert.Equal(suite.T(), testUser.FacebookID.String, user.FacebookID.String)
assert.Equal(suite.T(), testUser.FirstName.String, user.FirstName.String)
assert.Equal(suite.T(), testUser.LastName.String, user.LastName.String)
assert.Equal(suite.T(), testUser.Picture.String, user.Picture.String)
// Fetch oauth tokens
accessToken := new(oauth.AccessToken)
assert.False(suite.T(), oauth.AccessTokenPreload(suite.db).
First(accessToken).RecordNotFound())
refreshToken := new(oauth.RefreshToken)
assert.False(suite.T(), oauth.RefreshTokenPreload(suite.db).
//.........這裏部分代碼省略.........