util_test.go 922 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package testing
  2. import (
  3. "reflect"
  4. "testing"
  5. "devel.mephi.ru/iacherepanov/openstack-gophercloud/internal"
  6. )
  7. func TestRemainingKeys(t *testing.T) {
  8. type User struct {
  9. UserID string `json:"user_id"`
  10. Username string `json:"username"`
  11. Location string `json:"-"`
  12. CreatedAt string `json:"-"`
  13. Status string
  14. IsAdmin bool
  15. }
  16. userResponse := map[string]interface{}{
  17. "user_id": "abcd1234",
  18. "username": "jdoe",
  19. "location": "Hawaii",
  20. "created_at": "2017-06-08T02:49:03.000000",
  21. "status": "active",
  22. "is_admin": "true",
  23. "custom_field": "foo",
  24. }
  25. expected := map[string]interface{}{
  26. "created_at": "2017-06-08T02:49:03.000000",
  27. "is_admin": "true",
  28. "custom_field": "foo",
  29. }
  30. actual := internal.RemainingKeys(User{}, userResponse)
  31. isEqual := reflect.DeepEqual(expected, actual)
  32. if !isEqual {
  33. t.Fatalf("expected %s but got %s", expected, actual)
  34. }
  35. }