Joe Topjian | 1e9551c | 2017-06-03 10:35:33 -0600 | [diff] [blame] | 1 | package testing |
| 2 | |
| 3 | import ( |
Joe Topjian | fb5c0e8 | 2017-06-10 20:52:58 -0600 | [diff] [blame] | 4 | "reflect" |
Joe Topjian | 1e9551c | 2017-06-03 10:35:33 -0600 | [diff] [blame] | 5 | "testing" |
| 6 | |
| 7 | "gerrit.mcp.mirantis.net/debian/gophercloud.git/internal" |
Joe Topjian | 1e9551c | 2017-06-03 10:35:33 -0600 | [diff] [blame] | 8 | ) |
| 9 | |
| 10 | func TestRemainingKeys(t *testing.T) { |
| 11 | type User struct { |
Joe Topjian | fb5c0e8 | 2017-06-10 20:52:58 -0600 | [diff] [blame] | 12 | UserID string `json:"user_id"` |
| 13 | Username string `json:"username"` |
| 14 | Location string `json:"-"` |
| 15 | CreatedAt string `json:"-"` |
| 16 | Status string |
| 17 | IsAdmin bool |
Joe Topjian | 1e9551c | 2017-06-03 10:35:33 -0600 | [diff] [blame] | 18 | } |
| 19 | |
Joe Topjian | fb5c0e8 | 2017-06-10 20:52:58 -0600 | [diff] [blame] | 20 | userResponse := map[string]interface{}{ |
| 21 | "user_id": "abcd1234", |
| 22 | "username": "jdoe", |
| 23 | "location": "Hawaii", |
| 24 | "created_at": "2017-06-08T02:49:03.000000", |
| 25 | "status": "active", |
| 26 | "is_admin": "true", |
| 27 | "custom_field": "foo", |
Joe Topjian | 1e9551c | 2017-06-03 10:35:33 -0600 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | expected := map[string]interface{}{ |
Joe Topjian | fb5c0e8 | 2017-06-10 20:52:58 -0600 | [diff] [blame] | 31 | "created_at": "2017-06-08T02:49:03.000000", |
| 32 | "is_admin": "true", |
| 33 | "custom_field": "foo", |
Joe Topjian | 1e9551c | 2017-06-03 10:35:33 -0600 | [diff] [blame] | 34 | } |
| 35 | |
Joe Topjian | fb5c0e8 | 2017-06-10 20:52:58 -0600 | [diff] [blame] | 36 | actual := internal.RemainingKeys(User{}, userResponse) |
| 37 | |
| 38 | isEqual := reflect.DeepEqual(expected, actual) |
| 39 | if !isEqual { |
| 40 | t.Fatalf("expected %s but got %s", expected, actual) |
| 41 | } |
Joe Topjian | 1e9551c | 2017-06-03 10:35:33 -0600 | [diff] [blame] | 42 | } |