github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/internal/testing/util_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	"github.com/huaweicloud/golangsdk/internal"
     8  )
     9  
    10  func TestRemainingKeys(t *testing.T) {
    11  	type User struct {
    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
    18  	}
    19  
    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",
    28  	}
    29  
    30  	expected := map[string]interface{}{
    31  		"created_at":   "2017-06-08T02:49:03.000000",
    32  		"is_admin":     "true",
    33  		"custom_field": "foo",
    34  	}
    35  
    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  	}
    42  }