blob: 5cede6d57afc286ebcafc6d202d90ca8f341337d [file] [log] [blame]
Joe Topjian1e9551c2017-06-03 10:35:33 -06001package testing
2
3import (
Joe Topjianfb5c0e82017-06-10 20:52:58 -06004 "reflect"
Joe Topjian1e9551c2017-06-03 10:35:33 -06005 "testing"
6
7 "gerrit.mcp.mirantis.net/debian/gophercloud.git/internal"
Joe Topjian1e9551c2017-06-03 10:35:33 -06008)
9
10func TestRemainingKeys(t *testing.T) {
11 type User struct {
Joe Topjianfb5c0e82017-06-10 20:52:58 -060012 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 Topjian1e9551c2017-06-03 10:35:33 -060018 }
19
Joe Topjianfb5c0e82017-06-10 20:52:58 -060020 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 Topjian1e9551c2017-06-03 10:35:33 -060028 }
29
30 expected := map[string]interface{}{
Joe Topjianfb5c0e82017-06-10 20:52:58 -060031 "created_at": "2017-06-08T02:49:03.000000",
32 "is_admin": "true",
33 "custom_field": "foo",
Joe Topjian1e9551c2017-06-03 10:35:33 -060034 }
35
Joe Topjianfb5c0e82017-06-10 20:52:58 -060036 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 Topjian1e9551c2017-06-03 10:35:33 -060042}