-
-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored http package for more reliability
- Loading branch information
Showing
78 changed files
with
22,089 additions
and
75 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/********************************************************************************** | ||
* Copyright (c) 2009-2017 Misakai Ltd. | ||
* This program is free software: you can redistribute it and/or modify it under the | ||
* terms of the GNU Affero General Public License as published by the Free Software | ||
* Foundation, either version 3 of the License, or(at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
* PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License along | ||
* with this program. If not, see<http://www.gnu.org/licenses/>. | ||
************************************************************************************/ | ||
|
||
package http | ||
|
||
import ( | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
// MockClient is a mock implementation of Client | ||
type MockClient struct { | ||
mock.Mock | ||
} | ||
|
||
// NewMockClient returns a mock implementation of Client | ||
func NewMockClient() *MockClient { | ||
return &MockClient{ | ||
Mock: mock.Mock{}, | ||
} | ||
} | ||
|
||
// Get issues an HTTP Get on a specified URL and decodes the payload as JSON. | ||
func (mock *MockClient) Get(url string, output interface{}, headers ...HeaderValue) error { | ||
mockArgs := mock.Called(url, output, headers) | ||
return mockArgs.Error(0) | ||
} | ||
|
||
// Post is a utility function which marshals and issues an HTTP post on a specified URL. | ||
func (mock *MockClient) Post(url string, body []byte, output interface{}, headers ...HeaderValue) error { | ||
mockArgs := mock.Called(url, body, output, headers) | ||
return mockArgs.Error(0) | ||
} | ||
|
||
// PostJSON is a helper function which posts a JSON body with an appropriate content type. | ||
func (mock *MockClient) PostJSON(url string, body interface{}, output interface{}) (err error) { | ||
mockArgs := mock.Called(url, body, output) | ||
return mockArgs.Error(0) | ||
} | ||
|
||
// PostBinary is a helper function which posts a binary body with an appropriate content type. | ||
func (mock *MockClient) PostBinary(url string, body interface{}, output interface{}) (err error) { | ||
mockArgs := mock.Called(url, body, output) | ||
return mockArgs.Error(0) | ||
} |
Oops, something went wrong.