30 lines
547 B
Go
30 lines
547 B
Go
package discord
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"io"
|
|
"net/http"
|
|
|
|
"github.com/stretchr/testify/mock"
|
|
)
|
|
|
|
type DiscordClientMock struct {
|
|
mock.Mock
|
|
}
|
|
|
|
func (c *DiscordClientMock) Do(req *http.Request) (*http.Response, error) {
|
|
args := c.Called(req)
|
|
|
|
return args.Get(0).(*http.Response), args.Error(1)
|
|
}
|
|
|
|
func (c *DiscordClientMock) MockResponse(statusCode int, data any) *http.Response {
|
|
body := bytes.Buffer{}
|
|
json.NewEncoder(&body).Encode(data)
|
|
|
|
return &http.Response{
|
|
StatusCode: statusCode,
|
|
Body: io.NopCloser(&body),
|
|
}
|
|
}
|