mirror of
https://github.com/onedr0p/exportarr.git
synced 2026-02-06 10:57:32 +00:00
fix: Fix Query Param addition in client.go (#116)
Signed-off-by: Russell Troxel <russell.troxel@segment.com>
This commit is contained in:
parent
5834fa69fb
commit
05b277dec9
@ -94,15 +94,18 @@ func NewClient(c *cli.Context, cf *model.Config) (*Client, error) {
|
||||
|
||||
// DoRequest - Take a HTTP Request and return Unmarshaled data
|
||||
func (c *Client) DoRequest(endpoint string, target interface{}, queryParams ...map[string]string) error {
|
||||
values := c.URL.Query()
|
||||
for _, m := range queryParams {
|
||||
for k, v := range m {
|
||||
c.URL.Query().Add(k, v)
|
||||
values.Add(k, v)
|
||||
}
|
||||
}
|
||||
url := c.URL.JoinPath(endpoint).String()
|
||||
log.Infof("Sending HTTP request to %s", url)
|
||||
url := c.URL.JoinPath(endpoint)
|
||||
url.RawQuery = values.Encode()
|
||||
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
log.Infof("Sending HTTP request to %s", url.String())
|
||||
|
||||
req, err := http.NewRequest("GET", url.String(), nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to create HTTP Request(%s): %w", url, err)
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ func TestDoRequest(t *testing.T) {
|
||||
{
|
||||
name: "noParams",
|
||||
endpoint: "queue",
|
||||
expectedURL: "http://localhost:7878/api/v3/queue",
|
||||
expectedURL: "/api/v3/queue",
|
||||
},
|
||||
{
|
||||
name: "params",
|
||||
@ -91,13 +91,14 @@ func TestDoRequest(t *testing.T) {
|
||||
"page": "1",
|
||||
"testParam": "asdf",
|
||||
},
|
||||
expectedURL: "http://localhost:7878/api/v3/test?page=1&testParam=asdf",
|
||||
expectedURL: "/api/v3/test?page=1&testParam=asdf",
|
||||
},
|
||||
}
|
||||
for _, param := range parameters {
|
||||
t.Run(param.name, func(t *testing.T) {
|
||||
require := require.New(t)
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
require.Equal(param.expectedURL, r.URL.String(), "DoRequest should use the correct URL")
|
||||
fmt.Fprintln(w, "{\"test\": \"asdf2\"}")
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user