Add support for using freeleech tokens if available

This commit is contained in:
Daniel Mason 2025-07-11 10:12:43 +12:00
parent 74f777340e
commit 1242c19883
Signed by: idanoo
GPG key ID: 387387CDBC02F132
21 changed files with 88 additions and 34 deletions

View file

@ -70,7 +70,7 @@ func TestOrpheusClient_GetTorrentByID(t *testing.T) {
Url: ts.URL,
APIKey: key,
},
args: args{torrentID: "2156788"},
args: args{torrentID: "2156788", freeleechToken: false},
want: &domain.TorrentBasic{
Id: "2156788",
InfoHash: "",
@ -86,7 +86,7 @@ func TestOrpheusClient_GetTorrentByID(t *testing.T) {
Url: ts.URL,
APIKey: key,
},
args: args{torrentID: "100002"},
args: args{torrentID: "100002", freeleechToken: false},
want: nil,
wantErr: "could not get torrent by id: 100002: status code: 400 status: failure error: bad id parameter",
},
@ -96,16 +96,26 @@ func TestOrpheusClient_GetTorrentByID(t *testing.T) {
Url: ts.URL,
APIKey: "",
},
args: args{torrentID: "100002"},
args: args{torrentID: "100002", freeleechToken: false},
want: nil,
wantErr: "could not get torrent by id: 100002: orpheus client missing API key!",
},
{
name: "get_by_id_1_freeleech_token",
fields: fields{
Url: ts.URL,
APIKey: "",
},
args: args{torrentID: "100002", freeleechToken: true},
want: nil,
wantErr: "could not get torrent by id: 1. freeleech token not supported or no tokens available",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := NewClient(tt.fields.APIKey, WithUrl(ts.URL))
got, err := c.GetTorrentByID(context.Background(), tt.args.torrentID)
got, err := c.GetTorrentByID(context.Background(), tt.args.torrentID, tt.args.freeleechToken)
if tt.wantErr != "" && assert.Error(t, err) {
assert.EqualErrorf(t, err, tt.wantErr, "Error should be: %v, got: %v", tt.wantErr, err)
}