From 2c5a4a75f10839ce2e8d815d1f0851e40e190cdc Mon Sep 17 00:00:00 2001 From: fabiante <7669818+fabiante@users.noreply.github.com> Date: Sat, 10 Feb 2024 11:12:38 +0000 Subject: [PATCH] Add test --- client_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/client_test.go b/client_test.go index 1f291d12..b91f2e91 100644 --- a/client_test.go +++ b/client_test.go @@ -1069,3 +1069,29 @@ func TestUnixSocket(t *testing.T) { assertNil(t, err) assertEqual(t, "Hello resty client from a server running on endpoint /hello!", res.String()) } + +func TestClone(t *testing.T) { + parent := New() + + // set a non-interface field + parent.SetBaseURL("http://localhost") + + // set an interface field + parent.UserInfo = &User{ + Username: "parent", + } + + clone := parent.Clone() + // update value of non-interface type - change will only happen on clone + clone.SetBaseURL("https://local.host") + // update value of interface type - change will also happen on parent + clone.UserInfo.Username = "clone" + + // asert non-interface type + assertEqual(t, "http://localhost", parent.BaseURL) + assertEqual(t, "https://local.host", clone.BaseURL) + + // assert interface type + assertEqual(t, "clone", parent.UserInfo.Username) + assertEqual(t, "clone", clone.UserInfo.Username) +}