Skip to content

Commit

Permalink
Make tests pass with sorted dag-json output
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Jul 16, 2021
1 parent 26a6fb7 commit 019d85c
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 10 deletions.
6 changes: 5 additions & 1 deletion codec/dagjson/roundtripBytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ var byteNode = fluent.MustBuildMap(basicnode.Prototype__Map{}, 4, func(na fluent
na.AssembleEntry("plain").AssignString("olde string")
na.AssembleEntry("bytes").AssignBytes([]byte("deadbeef"))
})
var byteNodeSorted = fluent.MustBuildMap(basicnode.Prototype__Map{}, 4, func(na fluent.MapAssembler) {
na.AssembleEntry("bytes").AssignBytes([]byte("deadbeef"))
na.AssembleEntry("plain").AssignString("olde string")
})
var byteSerial = `{"bytes":{"/":{"bytes":"ZGVhZGJlZWY="}},"plain":"olde string"}`

func TestRoundtripBytes(t *testing.T) {
Expand All @@ -29,7 +33,7 @@ func TestRoundtripBytes(t *testing.T) {
nb := basicnode.Prototype__Map{}.NewBuilder()
err := Decode(nb, buf)
Require(t, err, ShouldEqual, nil)
Wish(t, nb.Build(), ShouldEqual, byteNode)
Wish(t, nb.Build(), ShouldEqual, byteNodeSorted)
})
}

Expand Down
2 changes: 1 addition & 1 deletion codec/dagjson/roundtripCidlink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestRoundtripCidlink(t *testing.T) {

n2, err := lsys.Load(ipld.LinkContext{}, lnk, basicnode.Prototype.Any)
Require(t, err, ShouldEqual, nil)
Wish(t, n2, ShouldEqual, n)
Wish(t, n2, ShouldEqual, nSorted)
}

// Make sure that a map that *almost* looks like a link is handled safely.
Expand Down
18 changes: 17 additions & 1 deletion codec/dagjson/roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ var n = fluent.MustBuildMap(basicnode.Prototype__Map{}, 4, func(na fluent.MapAss
})
})
})
var nSorted = fluent.MustBuildMap(basicnode.Prototype__Map{}, 4, func(na fluent.MapAssembler) {
na.AssembleEntry("list").CreateList(2, func(na fluent.ListAssembler) {
na.AssembleValue().AssignString("three")
na.AssembleValue().AssignString("four")
})
na.AssembleEntry("map").CreateMap(2, func(na fluent.MapAssembler) {
na.AssembleEntry("one").AssignInt(1)
na.AssembleEntry("two").AssignInt(2)
})
na.AssembleEntry("nested").CreateMap(1, func(na fluent.MapAssembler) {
na.AssembleEntry("deeper").CreateList(1, func(na fluent.ListAssembler) {
na.AssembleValue().AssignString("things")
})
})
na.AssembleEntry("plain").AssignString("olde string")
})
var serial = `{"list":["three","four"],"map":{"one":1,"two":2},"nested":{"deeper":["things"]},"plain":"olde string"}`

func TestRoundtrip(t *testing.T) {
Expand All @@ -41,7 +57,7 @@ func TestRoundtrip(t *testing.T) {
nb := basicnode.Prototype__Map{}.NewBuilder()
err := Decode(nb, buf)
Require(t, err, ShouldEqual, nil)
Wish(t, nb.Build(), ShouldEqual, n)
Wish(t, nb.Build(), ShouldEqual, nSorted)
})
}

Expand Down
2 changes: 1 addition & 1 deletion fluent/qp/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ func Example() {
dagjson.Encode(n, os.Stdout)

// Output:
// {"some key":"some value","another key":"another value","nested map":{"deeper entries":"deeper values","more deeper entries":"more deeper values"},"nested list":[1,2]}
// {"another key":"another value","nested list":[1,2],"nested map":{"deeper entries":"deeper values","more deeper entries":"more deeper values"},"some key":"some value"}
}
4 changes: 2 additions & 2 deletions node/bindnode/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func ExampleWrap_withSchema() {
dagjson.Encode(nodeRepr, os.Stdout)

// Output:
// {"Name":"Michael","Friends":["Sarah","Alex"]}
// {"Friends":["Sarah","Alex"],"Name":"Michael"}
}

func ExamplePrototype_onlySchema() {
Expand Down Expand Up @@ -78,5 +78,5 @@ func ExamplePrototype_onlySchema() {
dagjson.Encode(nodeRepr, os.Stdout)

// Output:
// {"Name":"Michael","Friends":["Sarah","Alex"]}
// {"Friends":["Sarah","Alex"],"Name":"Michael"}
}
6 changes: 3 additions & 3 deletions node/tests/schemaStructsContainingMaybe.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func SchemaTestStructsContainingMaybe(t *testing.T, engine Engine) {
{
name: "vvvvv-AllFieldsSet",
typeJson: `{"f1":"a","f2":"b","f3":"c","f4":"d","f5":"e"}`,
reprJson: `{"r1":"a","r2":"b","r3":"c","r4":"d","f5":"e"}`,
reprJson: `{"f5":"e","r1":"a","r2":"b","r3":"c","r4":"d"}`,
typePoints: []testcasePoint{
{"", ipld.Kind_Map},
{"f1", "a"},
Expand All @@ -68,7 +68,7 @@ func SchemaTestStructsContainingMaybe(t *testing.T, engine Engine) {
{
name: "vvnnv-Nulls",
typeJson: `{"f1":"a","f2":"b","f3":null,"f4":null,"f5":"e"}`,
reprJson: `{"r1":"a","r2":"b","r3":null,"r4":null,"f5":"e"}`,
reprJson: `{"f5":"e","r1":"a","r2":"b","r3":null,"r4":null}`,
typePoints: []testcasePoint{
{"", ipld.Kind_Map},
{"f1", "a"},
Expand All @@ -89,7 +89,7 @@ func SchemaTestStructsContainingMaybe(t *testing.T, engine Engine) {
{
name: "vzvzv-AbsentOptionals",
typeJson: `{"f1":"a","f3":"c","f5":"e"}`,
reprJson: `{"r1":"a","r3":"c","f5":"e"}`,
reprJson: `{"f5":"e","r1":"a","r3":"c"}`,
typePoints: []testcasePoint{
{"", ipld.Kind_Map},
{"f1", "a"},
Expand Down
2 changes: 1 addition & 1 deletion traversal/focus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func TestFocusedTransformWithLinks(t *testing.T) {
Wish(t, progress.Path.String(), ShouldEqual, "linkedMap/nested/nonlink")
Wish(t, must.String(prev), ShouldEqual, "zoo")
Wish(t, progress.LastBlock.Path.String(), ShouldEqual, "linkedMap")
Wish(t, progress.LastBlock.Link.String(), ShouldEqual, "baguqeeye2opztzy")
Wish(t, progress.LastBlock.Link.String(), ShouldEqual, "baguqeeyezhlahvq")
nb := prev.Prototype().NewBuilder()
nb.AssignString("new string!")
return nb.Build(), nil
Expand Down

0 comments on commit 019d85c

Please sign in to comment.