155 lines
6.0 KiB
Go
155 lines
6.0 KiB
Go
package component
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
|
|
metadataPb "homelab.lan/music-agregator/gen/metadata/v1"
|
|
"homelab.lan/music-agregator/internal/indexer"
|
|
"homelab.lan/music-agregator/internal/torrent"
|
|
)
|
|
|
|
type mockMetadataClient struct {
|
|
GetAlbumFunc func(ctx context.Context, in *metadataPb.GetAlbumRequest, opts ...grpc.CallOption) (*metadataPb.GetAlbumResponse, error)
|
|
GetArtistAlbumsFunc func(ctx context.Context, in *metadataPb.GetArtistAlbumsRequest, opts ...grpc.CallOption) (*metadataPb.GetArtistAlbumsResponse, error)
|
|
GetAlbumTracksFunc func(ctx context.Context, in *metadataPb.GetAlbumTracksRequest, opts ...grpc.CallOption) (*metadataPb.GetAlbumTracksResponse, error)
|
|
GetArtistFunc func(ctx context.Context, in *metadataPb.GetArtistRequest, opts ...grpc.CallOption) (*metadataPb.GetArtistResponse, error)
|
|
SearchArtistsFunc func(ctx context.Context, in *metadataPb.SearchArtistsRequest, opts ...grpc.CallOption) (*metadataPb.SearchArtistsResponse, error)
|
|
GetTrackFunc func(ctx context.Context, in *metadataPb.GetTrackRequest, opts ...grpc.CallOption) (*metadataPb.GetTrackResponse, error)
|
|
SearchAlbumsFunc func(ctx context.Context, in *metadataPb.SearchAlbumsRequest, opts ...grpc.CallOption) (*metadataPb.SearchAlbumsResponse, error)
|
|
SyncArtistFunc func(ctx context.Context, in *metadataPb.SyncArtistRequest, opts ...grpc.CallOption) (*metadataPb.SyncArtistResponse, error)
|
|
}
|
|
|
|
func (m *mockMetadataClient) GetAlbum(ctx context.Context, in *metadataPb.GetAlbumRequest, opts ...grpc.CallOption) (*metadataPb.GetAlbumResponse, error) {
|
|
if m.GetAlbumFunc != nil {
|
|
return m.GetAlbumFunc(ctx, in, opts...)
|
|
}
|
|
return nil, status.Error(codes.Unimplemented, "not mocked")
|
|
}
|
|
|
|
func (m *mockMetadataClient) GetArtistAlbums(ctx context.Context, in *metadataPb.GetArtistAlbumsRequest, opts ...grpc.CallOption) (*metadataPb.GetArtistAlbumsResponse, error) {
|
|
if m.GetArtistAlbumsFunc != nil {
|
|
return m.GetArtistAlbumsFunc(ctx, in, opts...)
|
|
}
|
|
return nil, status.Error(codes.Unimplemented, "not mocked")
|
|
}
|
|
|
|
func (m *mockMetadataClient) GetAlbumTracks(ctx context.Context, in *metadataPb.GetAlbumTracksRequest, opts ...grpc.CallOption) (*metadataPb.GetAlbumTracksResponse, error) {
|
|
if m.GetAlbumTracksFunc != nil {
|
|
return m.GetAlbumTracksFunc(ctx, in, opts...)
|
|
}
|
|
return nil, status.Error(codes.Unimplemented, "not mocked")
|
|
}
|
|
|
|
func (m *mockMetadataClient) GetArtist(ctx context.Context, in *metadataPb.GetArtistRequest, opts ...grpc.CallOption) (*metadataPb.GetArtistResponse, error) {
|
|
if m.GetArtistFunc != nil {
|
|
return m.GetArtistFunc(ctx, in, opts...)
|
|
}
|
|
return nil, status.Error(codes.Unimplemented, "not mocked")
|
|
}
|
|
|
|
func (m *mockMetadataClient) SearchArtists(ctx context.Context, in *metadataPb.SearchArtistsRequest, opts ...grpc.CallOption) (*metadataPb.SearchArtistsResponse, error) {
|
|
if m.SearchArtistsFunc != nil {
|
|
return m.SearchArtistsFunc(ctx, in, opts...)
|
|
}
|
|
return nil, status.Error(codes.Unimplemented, "not mocked")
|
|
}
|
|
|
|
func (m *mockMetadataClient) GetTrack(ctx context.Context, in *metadataPb.GetTrackRequest, opts ...grpc.CallOption) (*metadataPb.GetTrackResponse, error) {
|
|
if m.GetTrackFunc != nil {
|
|
return m.GetTrackFunc(ctx, in, opts...)
|
|
}
|
|
return nil, status.Error(codes.Unimplemented, "not mocked")
|
|
}
|
|
|
|
func (m *mockMetadataClient) SearchAlbums(ctx context.Context, in *metadataPb.SearchAlbumsRequest, opts ...grpc.CallOption) (*metadataPb.SearchAlbumsResponse, error) {
|
|
if m.SearchAlbumsFunc != nil {
|
|
return m.SearchAlbumsFunc(ctx, in, opts...)
|
|
}
|
|
return nil, status.Error(codes.Unimplemented, "not mocked")
|
|
}
|
|
|
|
func (m *mockMetadataClient) SyncArtist(ctx context.Context, in *metadataPb.SyncArtistRequest, opts ...grpc.CallOption) (*metadataPb.SyncArtistResponse, error) {
|
|
if m.SyncArtistFunc != nil {
|
|
return m.SyncArtistFunc(ctx, in, opts...)
|
|
}
|
|
return nil, status.Error(codes.Unimplemented, "not mocked")
|
|
}
|
|
|
|
type mockTorrentClient struct {
|
|
LoginFunc func(username, password string) (string, error)
|
|
ListFunc func() ([]torrent.TorrentInfo, error)
|
|
FindFunc func(opts torrent.FindOptions) ([]torrent.TorrentInfo, error)
|
|
AddTorrentFunc func(file torrent.TorrentFile, savePath string) error
|
|
AddMagnetFunc func(magnetURI string, savePath string) error
|
|
DefaultSavePathFunc func() (string, error)
|
|
}
|
|
|
|
func (m *mockTorrentClient) Login(username, password string) (string, error) {
|
|
if m.LoginFunc != nil {
|
|
return m.LoginFunc(username, password)
|
|
}
|
|
return "", fmt.Errorf("not mocked")
|
|
}
|
|
|
|
func (m *mockTorrentClient) List() ([]torrent.TorrentInfo, error) {
|
|
if m.ListFunc != nil {
|
|
return m.ListFunc()
|
|
}
|
|
return nil, fmt.Errorf("not mocked")
|
|
}
|
|
|
|
func (m *mockTorrentClient) Find(opts torrent.FindOptions) ([]torrent.TorrentInfo, error) {
|
|
if m.FindFunc != nil {
|
|
return m.FindFunc(opts)
|
|
}
|
|
return nil, fmt.Errorf("not mocked")
|
|
}
|
|
|
|
func (m *mockTorrentClient) AddTorrent(file torrent.TorrentFile, savePath string) error {
|
|
if m.AddTorrentFunc != nil {
|
|
return m.AddTorrentFunc(file, savePath)
|
|
}
|
|
return fmt.Errorf("not mocked")
|
|
}
|
|
|
|
func (m *mockTorrentClient) AddMagnet(magnetURI string, savePath string) error {
|
|
if m.AddMagnetFunc != nil {
|
|
return m.AddMagnetFunc(magnetURI, savePath)
|
|
}
|
|
return fmt.Errorf("not mocked")
|
|
}
|
|
|
|
func (m *mockTorrentClient) DefaultSavePath() (string, error) {
|
|
if m.DefaultSavePathFunc != nil {
|
|
return m.DefaultSavePathFunc()
|
|
}
|
|
return "/downloads", nil
|
|
}
|
|
|
|
type mockSearcher struct {
|
|
SearchFunc func(query string, limit int32, indexer string) (*indexer.SearchResponse, error)
|
|
}
|
|
|
|
func (m *mockSearcher) Search(query string, limit int32, idx string) (*indexer.SearchResponse, error) {
|
|
if m.SearchFunc != nil {
|
|
return m.SearchFunc(query, limit, idx)
|
|
}
|
|
return nil, fmt.Errorf("not mocked")
|
|
}
|
|
|
|
type mockResolver struct {
|
|
ResolveFunc func(magnetURI string) ([]byte, error)
|
|
}
|
|
|
|
func (m *mockResolver) Resolve(magnetURI string) ([]byte, error) {
|
|
if m.ResolveFunc != nil {
|
|
return m.ResolveFunc(magnetURI)
|
|
}
|
|
return nil, fmt.Errorf("not mocked")
|
|
}
|