Created
January 3, 2018 09:54
-
-
Save sbose78/f81d87dd6d52e8eb478052e71a2ee19f to your computer and use it in GitHub Desktop.
mocking a service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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