internal: Add RemainingKeys function (#351)
* internal: Add RemainingKeys function
This commit adds the RemainingKeys function which can be used to
detect fields returned in response bodies but are not defined in
the resource's result struct.
* Refactor RemainingKeys to not alter original map
Related-PROD: PROD-28126
Change-Id: I0fac3ae32dbce5be4f66945e68f4166f244ba613
diff --git a/internal/testing/util_test.go b/internal/testing/util_test.go
new file mode 100644
index 0000000..a4f03ef
--- /dev/null
+++ b/internal/testing/util_test.go
@@ -0,0 +1,36 @@
+package testing
+
+import (
+ "testing"
+
+ "gerrit.mcp.mirantis.net/debian/gophercloud.git/internal"
+ th "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper"
+)
+
+func TestRemainingKeys(t *testing.T) {
+ type User struct {
+ FirstName string `json:"first_name"`
+ LastName string `json:"last_name"`
+ City string
+ }
+
+ userStruct := User{
+ FirstName: "John",
+ LastName: "Doe",
+ }
+
+ userMap := map[string]interface{}{
+ "first_name": "John",
+ "last_name": "Doe",
+ "city": "Honolulu",
+ "state": "Hawaii",
+ }
+
+ expected := map[string]interface{}{
+ "city": "Honolulu",
+ "state": "Hawaii",
+ }
+
+ actual := internal.RemainingKeys(userStruct, userMap)
+ th.AssertDeepEquals(t, expected, actual)
+}