mirror of
https://github.com/sstent/go-garth.git
synced 2026-01-26 09:03:00 +00:00
sync
This commit is contained in:
24
garth/testutils/mock_client.go
Normal file
24
garth/testutils/mock_client.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package testutils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"net/url"
|
||||
|
||||
"garmin-connect/garth/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)
|
||||
}
|
||||
Reference in New Issue
Block a user