rgw/admin: un-export mock client

We don't need to export the mock, the consumer will generate its own.
What really matters is to have an interface that consumer can mock it
desired. Reference: https://github.com/golang/go/wiki/CodeReviewComments#interfaces

Signed-off-by: Sébastien Han <seb@redhat.com>
This commit is contained in:
Sébastien Han 2021-07-22 11:25:30 +02:00 committed by mergify[bot]
parent 401fbe9698
commit 1a18c07193
2 changed files with 15 additions and 20 deletions

View File

@ -1,18 +0,0 @@
package admin
import (
"net/http"
)
// MockClient is the mock of the HTTP Client
// It can be used to mock HTTP request/response from the rgw admin ops API
type MockClient struct {
// MockDo is a type that mock the Do method from the HTTP package
MockDo MockDoType
}
// MockDoType is a custom type that allows setting the function that our Mock Do func will run instead
type MockDoType func(req *http.Request) (*http.Response, error)
// Do is the mock client's `Do` func
func (m *MockClient) Do(req *http.Request) (*http.Response, error) { return m.MockDo(req) }

View File

@ -13,6 +13,19 @@ import (
"github.com/stretchr/testify/assert"
)
// mockClient is the mock of the HTTP Client
// It can be used to mock HTTP request/response from the rgw admin ops API
type mockClient struct {
// mockDo is a type that mock the Do method from the HTTP package
mockDo mockDoType
}
// mockDoType is a custom type that allows setting the function that our Mock Do func will run instead
type mockDoType func(req *http.Request) (*http.Response, error)
// Do is the mock client's `Do` func
func (m *mockClient) Do(req *http.Request) (*http.Response, error) { return m.mockDo(req) }
var (
fakeUserResponse = []byte(`
{
@ -141,8 +154,8 @@ func (suite *RadosGWTestSuite) TestUser() {
func TestGetUserMockAPI(t *testing.T) {
r := ioutil.NopCloser(bytes.NewReader(fakeUserResponse))
mockClient := &MockClient{
MockDo: func(req *http.Request) (*http.Response, error) {
mockClient := &mockClient{
mockDo: func(req *http.Request) (*http.Response, error) {
if req.URL.RawQuery == "format=json&uid=dashboard-admin" && req.Method == http.MethodGet && req.URL.Path == "127.0.0.1/admin/user" {
return &http.Response{
StatusCode: 200,