github.com/spreadshirt/mattermost-server@v5.3.2-0.20180927191755-a257d501df3d+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  	"net/http"
     8  	"net/http/httptest"
     9  )
    10  
    11  type MockedHTTPService struct {
    12  	Server *httptest.Server
    13  }
    14  
    15  func MakeMockedHTTPService(handler http.Handler) *MockedHTTPService {
    16  	return &MockedHTTPService{
    17  		Server: httptest.NewServer(handler),
    18  	}
    19  }
    20  
    21  func (h *MockedHTTPService) MakeClient(trustURLs bool) *http.Client {
    22  	return h.Server.Client()
    23  }
    24  
    25  func (h *MockedHTTPService) Close() {
    26  	h.Server.CloseClientConnections()
    27  	h.Server.Close()
    28  }