Skip to content

Instantly share code, notes, and snippets.

@sbose78
Created January 3, 2018 09:54
Show Gist options
  • Save sbose78/f81d87dd6d52e8eb478052e71a2ee19f to your computer and use it in GitHub Desktop.
Save sbose78/f81d87dd6d52e8eb478052e71a2ee19f to your computer and use it in GitHub Desktop.
mocking a service
package main
type AuthUserProfileService interface{
Get() string
}
type AuthUserClient struct {
httpClient
config
}
func (c *AuthUserClient) talkToAuth(){
// something
}
func (c *AuthUserClient) Get() string{
return ""
}
--- main.go ---
authClient := AuthUserClient{
httpClient:
config:
}
NewUserController(authClient)
----------------------------------------------------------------
type UserController struct{
config
gormRepository
authUserProfileService AuthUserProfileService
}
func NewUserController(authProfileService AuthUserProfileService){
}
----------------------------------- tests -----
type mockUserService struct{}
func (m mockUserService) Get() string{
}
NewUserController(&mockUserService{})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment