mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +00:00
refactor: download client addr parsing (#108)
* refactor: client addr parsing * feat: add logging to client test * feat: imrpove help for download client forms
This commit is contained in:
parent
26f558859a
commit
fe25cdec28
7 changed files with 50 additions and 14 deletions
|
@ -4,14 +4,17 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (c *client) get(endpoint string) (*http.Response, error) {
|
||||
reqUrl := fmt.Sprintf("%v/api/v3/%v", c.config.Hostname, endpoint)
|
||||
u, err := url.Parse(c.config.Hostname)
|
||||
u.Path = path.Join(u.Path, "/api/v3/", endpoint)
|
||||
reqUrl := u.String()
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, reqUrl, http.NoBody)
|
||||
if err != nil {
|
||||
|
@ -40,7 +43,9 @@ func (c *client) get(endpoint string) (*http.Response, error) {
|
|||
}
|
||||
|
||||
func (c *client) post(endpoint string, data interface{}) (*http.Response, error) {
|
||||
reqUrl := fmt.Sprintf("%v/api/v3/%v", c.config.Hostname, endpoint)
|
||||
u, err := url.Parse(c.config.Hostname)
|
||||
u.Path = path.Join(u.Path, "/api/v3/", endpoint)
|
||||
reqUrl := u.String()
|
||||
|
||||
jsonData, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
|
|
|
@ -171,6 +171,19 @@ func Test_client_Test(t *testing.T) {
|
|||
wantErr: true,
|
||||
err: errors.New("unauthorized: bad credentials"),
|
||||
},
|
||||
{
|
||||
name: "fetch_subfolder",
|
||||
cfg: Config{
|
||||
Hostname: srv.URL + "/radarr",
|
||||
APIKey: key,
|
||||
BasicAuth: false,
|
||||
Username: "",
|
||||
Password: "",
|
||||
},
|
||||
want: &SystemStatusResponse{Version: "3.2.2.5080"},
|
||||
err: nil,
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue