Skip to content

Commit 2c5a4a7

Browse files
committed
Add test
1 parent 9152f3d commit 2c5a4a7

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

client_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -1069,3 +1069,29 @@ func TestUnixSocket(t *testing.T) {
10691069
assertNil(t, err)
10701070
assertEqual(t, "Hello resty client from a server running on endpoint /hello!", res.String())
10711071
}
1072+
1073+
func TestClone(t *testing.T) {
1074+
parent := New()
1075+
1076+
// set a non-interface field
1077+
parent.SetBaseURL("http://localhost")
1078+
1079+
// set an interface field
1080+
parent.UserInfo = &User{
1081+
Username: "parent",
1082+
}
1083+
1084+
clone := parent.Clone()
1085+
// update value of non-interface type - change will only happen on clone
1086+
clone.SetBaseURL("https://local.host")
1087+
// update value of interface type - change will also happen on parent
1088+
clone.UserInfo.Username = "clone"
1089+
1090+
// asert non-interface type
1091+
assertEqual(t, "http://localhost", parent.BaseURL)
1092+
assertEqual(t, "https://local.host", clone.BaseURL)
1093+
1094+
// assert interface type
1095+
assertEqual(t, "clone", parent.UserInfo.Username)
1096+
assertEqual(t, "clone", clone.UserInfo.Username)
1097+
}

0 commit comments

Comments
 (0)