2022-08-06 08:12:45 +00:00
|
|
|
package clients
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"net/url"
|
|
|
|
|
2022-08-07 06:29:35 +00:00
|
|
|
"github.com/fmartingr/bazaar/internal/mockdata"
|
2022-08-06 08:12:45 +00:00
|
|
|
)
|
|
|
|
|
2022-08-07 06:29:35 +00:00
|
|
|
// MockClient A simple client used for test the shops which will load an HTML from the mockdata present
|
|
|
|
// in this same package based on the requested host.
|
2022-08-06 08:12:45 +00:00
|
|
|
type MockClient struct{}
|
|
|
|
|
2022-08-07 10:01:21 +00:00
|
|
|
func (c MockClient) Get(u *url.URL) (io.Reader, error) {
|
|
|
|
f, err := mockdata.Data.Open(u.Host + ".html")
|
2022-08-06 08:12:45 +00:00
|
|
|
if err != nil {
|
2022-08-07 10:01:21 +00:00
|
|
|
return nil, fmt.Errorf("can't open mock data for %s", u.Host)
|
2022-08-06 08:12:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return f, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMockClient() MockClient {
|
|
|
|
return MockClient{}
|
|
|
|
}
|