forked from Mirrors/jsonapi
89 lines
1.3 KiB
Go
89 lines
1.3 KiB
Go
|
package jsonapi
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"reflect"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func isJSONEqual(b1, b2 []byte) (bool, error) {
|
||
|
var i1, i2 interface{}
|
||
|
var result bool
|
||
|
var err error
|
||
|
if err = json.Unmarshal(b1, &i1); err != nil {
|
||
|
return result, err
|
||
|
}
|
||
|
if err = json.Unmarshal(b2, &i2); err != nil {
|
||
|
return result, err
|
||
|
}
|
||
|
result = reflect.DeepEqual(i1, i2)
|
||
|
return result, err
|
||
|
}
|
||
|
|
||
|
func testBlog() *Blog {
|
||
|
return &Blog{
|
||
|
ID: 5,
|
||
|
Title: "Title 1",
|
||
|
CreatedAt: time.Now(),
|
||
|
Posts: []*Post{
|
||
|
&Post{
|
||
|
ID: 1,
|
||
|
Title: "Foo",
|
||
|
Body: "Bar",
|
||
|
Comments: []*Comment{
|
||
|
&Comment{
|
||
|
ID: 1,
|
||
|
Body: "foo",
|
||
|
},
|
||
|
&Comment{
|
||
|
ID: 2,
|
||
|
Body: "bar",
|
||
|
},
|
||
|
},
|
||
|
LatestComment: &Comment{
|
||
|
ID: 1,
|
||
|
Body: "foo",
|
||
|
},
|
||
|
},
|
||
|
&Post{
|
||
|
ID: 2,
|
||
|
Title: "Fuubar",
|
||
|
Body: "Bas",
|
||
|
Comments: []*Comment{
|
||
|
&Comment{
|
||
|
ID: 1,
|
||
|
Body: "foo",
|
||
|
},
|
||
|
&Comment{
|
||
|
ID: 3,
|
||
|
Body: "bas",
|
||
|
},
|
||
|
},
|
||
|
LatestComment: &Comment{
|
||
|
ID: 1,
|
||
|
Body: "foo",
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
CurrentPost: &Post{
|
||
|
ID: 1,
|
||
|
Title: "Foo",
|
||
|
Body: "Bar",
|
||
|
Comments: []*Comment{
|
||
|
&Comment{
|
||
|
ID: 1,
|
||
|
Body: "foo",
|
||
|
},
|
||
|
&Comment{
|
||
|
ID: 2,
|
||
|
Body: "bar",
|
||
|
},
|
||
|
},
|
||
|
LatestComment: &Comment{
|
||
|
ID: 1,
|
||
|
Body: "foo",
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
}
|