mirror of
https://github.com/sstent/go-garth-cli.git
synced 2025-12-06 08:02:01 +00:00
25 lines
526 B
Go
25 lines
526 B
Go
package testutils
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
"net/url"
|
|
|
|
"github.com/sstent/go-garth/api/client"
|
|
)
|
|
|
|
// MockClient simulates API client for tests
|
|
type MockClient struct {
|
|
RealClient *client.Client
|
|
FailEvery int
|
|
counter int
|
|
}
|
|
|
|
func (mc *MockClient) ConnectAPI(path string, method string, params url.Values, body io.Reader) ([]byte, error) {
|
|
mc.counter++
|
|
if mc.FailEvery != 0 && mc.counter%mc.FailEvery == 0 {
|
|
return nil, errors.New("simulated error")
|
|
}
|
|
return mc.RealClient.ConnectAPI(path, method, params, body)
|
|
}
|