Guest User

Untitled

a guest
Apr 26th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. type HttpClient interface {
  2. Do(req *http.Request) (*http.Response, error)
  3. }
  4.  
  5. func GetOverview(client HttpClient, overview *Overview) (*Overview, error) {
  6.  
  7. request, err := http.NewRequest("GET", fmt.Sprintf("%s:%s/api/overview", overview.Config.Url, overview.Config.Port), nil)
  8. if (err != nil) {
  9. log.Println(err)
  10. }
  11. request.SetBasicAuth(overview.Config.User, overview.Config.Password)
  12. resp, err := client.Do(request)
  13.  
  14. type ClientMock struct {
  15. }
  16.  
  17. func (c *ClientMock) Do(req *http.Request) (*http.Response, error) {
  18. return &http.Response{}, nil
  19. }
  20.  
  21. type HttpClient interface {
  22. Do(req *http.Request) (*http.Response, error)
  23. }
  24.  
  25. type MockClient struct {
  26. DoFunc func(req *http.Request) (*http.Response, error)
  27. }
  28.  
  29. func (m *MockClient) Do(req *http.Request) (*http.Response, error) {
  30. if m.DoFunc != nil {
  31. return m.DoFunc(req)
  32. }
  33. return &http.Response{}, nil
  34. }
Add Comment
Please, Sign In to add comment