本文整理匯總了Golang中bitbucket/org/msamson/doorbot-api/tests.MockAccountRepository.AssertExpectations方法的典型用法代碼示例。如果您正苦於以下問題:Golang MockAccountRepository.AssertExpectations方法的具體用法?Golang MockAccountRepository.AssertExpectations怎麽用?Golang MockAccountRepository.AssertExpectations使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類bitbucket/org/msamson/doorbot-api/tests.MockAccountRepository
的用法示例。
在下文中一共展示了MockAccountRepository.AssertExpectations方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestAuthPassword_UserNotFound
func TestAuthPassword_UserNotFound(t *testing.T) {
requestBody, _ := json.Marshal(auth.PasswordRequest{
Authentication: auth.PasswordAuthentication{
Email: "[email protected]",
Password: "test",
},
})
req, _ := http.NewRequest("POST", "/api/auth/password", bytes.NewBuffer(requestBody))
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Host", "account.example.com")
req.Header.Add("Authorization", "dashboard gatekeeper")
rec := httptest.NewRecorder()
server := newServer()
account := &doorbot.Account{
ID: 45,
}
var person *doorbot.Person
accountRepo := new(tests.MockAccountRepository)
authRepo := new(tests.MockAuthenticationRepository)
personRepo := new(tests.MockPersonRepository)
db := new(tests.MockExecutor)
repos := getDependency(server, (*doorbot.Repositories)(nil)).(*tests.MockRepositories)
repos.On("SetAccountScope", uint(45)).Return()
repos.On("AccountRepository").Return(accountRepo)
repos.On("AuthenticationRepository").Return(authRepo)
repos.On("PersonRepository").Return(personRepo)
repos.On("DB").Return(db)
accountRepo.On("FindByHost", db, "account").Return(account, nil)
personRepo.On("FindByEmail", db, "[email protected]").Return(person, nil)
server.ServeHTTP(rec, req)
assert.Equal(t, http.StatusUnauthorized, rec.Code)
repos.AssertExpectations(t)
personRepo.AssertExpectations(t)
accountRepo.AssertExpectations(t)
}