github.com/jlevesy/mattermost-server@v5.3.2-0.20181003190404-7468f35cb0c8+incompatible/utils/testutils/mocked_http_service.go (about)

     1  // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package testutils
     5  
     6  import (
     7  	"github.com/mattermost/mattermost-server/services/httpservice"
     8  	"net/http"
     9  	"net/http/httptest"
    10  )
    11  
    12  type MockedHTTPService struct {
    13  	Server *httptest.Server
    14  }
    15  
    16  func MakeMockedHTTPService(handler http.Handler) *MockedHTTPService {
    17  	return &MockedHTTPService{
    18  		Server: httptest.NewServer(handler),
    19  	}
    20  }
    21  
    22  func (h *MockedHTTPService) MakeClient(trustURLs bool) *httpservice.Client {
    23  	return &httpservice.Client{Client: h.Server.Client()}
    24  }
    25  
    26  func (h *MockedHTTPService) Close() {
    27  	h.Server.CloseClientConnections()
    28  	h.Server.Close()
    29  }