Skip to content

Commit

Permalink
Merge branch 'go-resty:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtleRuss authored and tttturtle-russ committed Sep 9, 2024
2 parents 1dbee6d + b69c496 commit 15f9912
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
18 changes: 16 additions & 2 deletions request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2187,12 +2187,12 @@ func TestRequestClone(t *testing.T) {

// set an non-interface value
parent.URL = ts.URL
parent.SetPathParams(map[string]string{"name": "parent"})
parent.SetPathParam("name", "parent")
parent.SetRawPathParam("name", "parent")
// set http header
parent.SetHeader("X-Header", "parent")
// set an interface value
parent.SetBasicAuth("parent", "")

clone := parent.Clone(context.Background())

// assume parent request is used
Expand All @@ -2201,6 +2201,7 @@ func TestRequestClone(t *testing.T) {
// update value of non-interface type - change will only happen on clone
clone.URL = "http://localhost.clone"
clone.PathParams["name"] = "clone"
clone.RawPathParams["name"] = "clone"
// update value of http header - change will only happen on clone
clone.SetHeader("X-Header", "clone")
// update value of interface type - change will only happen on clone
Expand All @@ -2211,6 +2212,8 @@ func TestRequestClone(t *testing.T) {
assertEqual(t, ts.URL, parent.URL)
assertEqual(t, "clone", clone.PathParams["name"])
assertEqual(t, "parent", parent.PathParams["name"])
assertEqual(t, "clone", clone.RawPathParams["name"])
assertEqual(t, "parent", parent.RawPathParams["name"])
// assert http header
assertEqual(t, "parent", parent.Header.Get("X-Header"))
assertEqual(t, "clone", clone.Header.Get("X-Header"))
Expand All @@ -2221,4 +2224,15 @@ func TestRequestClone(t *testing.T) {
// parent request should have raw request while clone should not
assertNil(t, clone.RawRequest)
assertNotNil(t, parent.RawRequest)
assertNotEqual(t, parent.RawRequest, clone.RawRequest)

// test SRV
parent = c.R()
parent.SetSRV(&SRVRecord{"xmpp-server", "google.com"})

clone = parent.Clone(context.Background())
clone.SRV.Service = "xmpp-server-clone"

assertEqual(t, "xmpp-server", parent.SRV.Service)
assertEqual(t, "xmpp-server-clone", clone.SRV.Service)
}
11 changes: 11 additions & 0 deletions util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package resty
import (
"bytes"
"mime/multipart"
"net/url"
"testing"
)

Expand Down Expand Up @@ -89,3 +90,13 @@ func TestWriteMultipartFormFileReaderError(t *testing.T) {
assertNotNil(t, err)
assertEqual(t, "read error", err.Error())
}

func TestCloneURLValues(t *testing.T) {
v := url.Values{}
v.Add("foo", "bar")
v.Add("foo", "baz")
v.Add("qux", "quux")

c := cloneURLValues(v)
assertEqual(t, v, c)
}

0 comments on commit 15f9912

Please sign in to comment.