mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00

* refactor(indexers): test api clients * feat(indexers): test api connection * fix(indexers): api client tests * refactor: indexer api clients * feat: add Toasts for indexer api tests * fix: failing red tests
47 lines
933 B
Go
47 lines
933 B
Go
package mock
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/autobrr/autobrr/internal/domain"
|
|
"github.com/autobrr/autobrr/pkg/errors"
|
|
)
|
|
|
|
type IndexerApiClient interface {
|
|
GetTorrentByID(ctx context.Context, torrentID string) (*domain.TorrentBasic, error)
|
|
TestAPI(ctx context.Context) (bool, error)
|
|
}
|
|
|
|
type IndexerClient struct {
|
|
URL string
|
|
APIKey string
|
|
}
|
|
|
|
func NewMockClient(url string, apiKey string) IndexerApiClient {
|
|
c := &IndexerClient{
|
|
URL: url,
|
|
APIKey: apiKey,
|
|
}
|
|
|
|
return c
|
|
}
|
|
|
|
func (c *IndexerClient) GetTorrentByID(ctx context.Context, torrentID string) (*domain.TorrentBasic, error) {
|
|
if torrentID == "" {
|
|
return nil, errors.New("mock client: must have torrentID")
|
|
}
|
|
|
|
r := &domain.TorrentBasic{
|
|
Id: torrentID,
|
|
InfoHash: "",
|
|
Size: "10GB",
|
|
}
|
|
|
|
return r, nil
|
|
|
|
}
|
|
|
|
// TestAPI try api access against torrents page
|
|
func (c *IndexerClient) TestAPI(ctx context.Context) (bool, error) {
|
|
return true, nil
|
|
}
|