github.com/seeker-insurance/kit@v0.0.13/jsonapi/helpers_test.go (about)

     1  package jsonapi
     2  
     3  import (
     4  	"encoding/json"
     5  	"reflect"
     6  	"time"
     7  )
     8  
     9  func isJSONEqual(b1, b2 []byte) (bool, error) {
    10  	var i1, i2 interface{}
    11  	var result bool
    12  	var err error
    13  	if err = json.Unmarshal(b1, &i1); err != nil {
    14  		return result, err
    15  	}
    16  	if err = json.Unmarshal(b2, &i2); err != nil {
    17  		return result, err
    18  	}
    19  	result = reflect.DeepEqual(i1, i2)
    20  	return result, err
    21  }
    22  
    23  func testBlog() *Blog {
    24  	return &Blog{
    25  		ID:        5,
    26  		Title:     "Title 1",
    27  		CreatedAt: time.Now(),
    28  		Posts: []*Post{
    29  			&Post{
    30  				ID:    1,
    31  				Title: "Foo",
    32  				Body:  "Bar",
    33  				Comments: []*Comment{
    34  					&Comment{
    35  						ID:   1,
    36  						Body: "foo",
    37  					},
    38  					&Comment{
    39  						ID:   2,
    40  						Body: "bar",
    41  					},
    42  				},
    43  				LatestComment: &Comment{
    44  					ID:   1,
    45  					Body: "foo",
    46  				},
    47  			},
    48  			&Post{
    49  				ID:    2,
    50  				Title: "Fuubar",
    51  				Body:  "Bas",
    52  				Comments: []*Comment{
    53  					&Comment{
    54  						ID:   1,
    55  						Body: "foo",
    56  					},
    57  					&Comment{
    58  						ID:   3,
    59  						Body: "bas",
    60  					},
    61  				},
    62  				LatestComment: &Comment{
    63  					ID:   1,
    64  					Body: "foo",
    65  				},
    66  			},
    67  		},
    68  		CurrentPost: &Post{
    69  			ID:    1,
    70  			Title: "Foo",
    71  			Body:  "Bar",
    72  			Comments: []*Comment{
    73  				&Comment{
    74  					ID:   1,
    75  					Body: "foo",
    76  				},
    77  				&Comment{
    78  					ID:   2,
    79  					Body: "bar",
    80  				},
    81  			},
    82  			LatestComment: &Comment{
    83  				ID:   1,
    84  				Body: "foo",
    85  			},
    86  		},
    87  	}
    88  }