當前位置: 首頁>>代碼示例>>Golang>>正文


Golang MockAccountRepository.AssertExpectations方法代碼示例

本文整理匯總了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)

}
開發者ID:masom,項目名稱:doorbot,代碼行數:46,代碼來源:api_auth_test.go


注:本文中的bitbucket/org/msamson/doorbot-api/tests.MockAccountRepository.AssertExpectations方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。