Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port codec package tests to quicktest #291

Merged
merged 1 commit into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions codec/cbor/roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"strings"
"testing"

. "github.com/warpfork/go-wish"
qt "github.com/frankban/quicktest"

"github.com/ipld/go-ipld-prime/fluent"
"github.com/ipld/go-ipld-prime/node/basicnode"
nodetests "github.com/ipld/go-ipld-prime/node/tests"
)

var n = fluent.MustBuildMap(basicnode.Prototype.Map, 4, func(na fluent.MapAssembler) {
Expand All @@ -34,15 +35,15 @@ func TestRoundtrip(t *testing.T) {
t.Run("encoding", func(t *testing.T) {
var buf bytes.Buffer
err := Encode(n, &buf)
Require(t, err, ShouldEqual, nil)
Wish(t, buf.String(), ShouldEqual, serial)
qt.Assert(t, err, qt.IsNil)
qt.Check(t, buf.String(), qt.Equals, serial)
})
t.Run("decoding", func(t *testing.T) {
buf := strings.NewReader(serial)
nb := basicnode.Prototype.Map.NewBuilder()
err := Decode(nb, buf)
Require(t, err, ShouldEqual, nil)
Wish(t, nb.Build(), ShouldEqual, n)
qt.Assert(t, err, qt.IsNil)
qt.Check(t, nb.Build(), nodetests.NodeContentEquals, n)
})
}

Expand All @@ -53,14 +54,14 @@ func TestRoundtripScalar(t *testing.T) {
t.Run("encoding", func(t *testing.T) {
var buf bytes.Buffer
err := Encode(simple, &buf)
Require(t, err, ShouldEqual, nil)
Wish(t, buf.String(), ShouldEqual, `japplesauce`)
qt.Assert(t, err, qt.IsNil)
qt.Check(t, buf.String(), qt.Equals, `japplesauce`)
})
t.Run("decoding", func(t *testing.T) {
buf := strings.NewReader(`japplesauce`)
nb := basicnode.Prototype__String{}.NewBuilder()
err := Decode(nb, buf)
Require(t, err, ShouldEqual, nil)
Wish(t, nb.Build(), ShouldEqual, simple)
qt.Assert(t, err, qt.IsNil)
qt.Check(t, nb.Build(), nodetests.NodeContentEquals, simple)
})
}
9 changes: 5 additions & 4 deletions codec/dagcbor/roundtripCidlink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (
"io"
"testing"

. "github.com/warpfork/go-wish"
qt "github.com/frankban/quicktest"

cid "github.com/ipfs/go-cid"
"github.com/ipld/go-ipld-prime/datamodel"
"github.com/ipld/go-ipld-prime/linking"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
"github.com/ipld/go-ipld-prime/node/basicnode"
nodetests "github.com/ipld/go-ipld-prime/node/tests"
)

func TestRoundtripCidlink(t *testing.T) {
Expand All @@ -32,9 +33,9 @@ func TestRoundtripCidlink(t *testing.T) {
}

lnk, err := lsys.Store(linking.LinkContext{}, lp, n)
Require(t, err, ShouldEqual, nil)
qt.Assert(t, err, qt.IsNil)

n2, err := lsys.Load(linking.LinkContext{}, lnk, basicnode.Prototype.Any)
Require(t, err, ShouldEqual, nil)
Wish(t, n2, ShouldEqual, nSorted)
qt.Assert(t, err, qt.IsNil)
qt.Check(t, n2, nodetests.NodeContentEquals, nSorted)
}
25 changes: 13 additions & 12 deletions codec/dagcbor/roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"strings"
"testing"

qt "github.com/frankban/quicktest"
cid "github.com/ipfs/go-cid"
. "github.com/warpfork/go-wish"

"github.com/ipld/go-ipld-prime/fluent"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
"github.com/ipld/go-ipld-prime/node/basicnode"
nodetests "github.com/ipld/go-ipld-prime/node/tests"
)

var n = fluent.MustBuildMap(basicnode.Prototype.Map, 4, func(na fluent.MapAssembler) {
Expand Down Expand Up @@ -52,15 +53,15 @@ func TestRoundtrip(t *testing.T) {
t.Run("encoding", func(t *testing.T) {
var buf bytes.Buffer
err := Encode(n, &buf)
Require(t, err, ShouldEqual, nil)
Wish(t, buf.String(), ShouldEqual, serial)
qt.Assert(t, err, qt.IsNil)
qt.Check(t, buf.String(), qt.Equals, serial)
})
t.Run("decoding", func(t *testing.T) {
buf := strings.NewReader(serial)
nb := basicnode.Prototype.Map.NewBuilder()
err := Decode(nb, buf)
Require(t, err, ShouldEqual, nil)
Wish(t, nb.Build(), ShouldEqual, nSorted)
qt.Assert(t, err, qt.IsNil)
qt.Check(t, nb.Build(), nodetests.NodeContentEquals, nSorted)
})
}

Expand All @@ -71,15 +72,15 @@ func TestRoundtripScalar(t *testing.T) {
t.Run("encoding", func(t *testing.T) {
var buf bytes.Buffer
err := Encode(simple, &buf)
Require(t, err, ShouldEqual, nil)
Wish(t, buf.String(), ShouldEqual, `japplesauce`)
qt.Assert(t, err, qt.IsNil)
qt.Check(t, buf.String(), qt.Equals, `japplesauce`)
})
t.Run("decoding", func(t *testing.T) {
buf := strings.NewReader(`japplesauce`)
nb := basicnode.Prototype__String{}.NewBuilder()
err := Decode(nb, buf)
Require(t, err, ShouldEqual, nil)
Wish(t, nb.Build(), ShouldEqual, simple)
qt.Assert(t, err, qt.IsNil)
qt.Check(t, nb.Build(), nodetests.NodeContentEquals, simple)
})
}

Expand All @@ -102,10 +103,10 @@ func TestRoundtripLinksAndBytes(t *testing.T) {

buf := bytes.Buffer{}
err := Encode(linkByteNode, &buf)
Require(t, err, ShouldEqual, nil)
qt.Assert(t, err, qt.IsNil)
nb := basicnode.Prototype.Map.NewBuilder()
err = Decode(nb, &buf)
Require(t, err, ShouldEqual, nil)
qt.Assert(t, err, qt.IsNil)
reconstructed := nb.Build()
Wish(t, reconstructed, ShouldEqual, linkByteNode)
qt.Check(t, reconstructed, nodetests.NodeContentEquals, linkByteNode)
}
10 changes: 5 additions & 5 deletions codec/dagcbor/unmarshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"strings"
"testing"

. "github.com/warpfork/go-wish"
qt "github.com/frankban/quicktest"

"github.com/ipld/go-ipld-prime/node/basicnode"
)
Expand All @@ -15,27 +15,27 @@ func TestFunBlocks(t *testing.T) {
buf := strings.NewReader("\x8d\x8d\x97\xd8*@")
nb := basicnode.Prototype.Any.NewBuilder()
err := Decode(nb, buf)
Require(t, err, ShouldEqual, ErrInvalidMultibase)
qt.Assert(t, err, qt.Equals, ErrInvalidMultibase)
})
t.Run("fuzz001", func(t *testing.T) {
// This fixture might cause an overly large allocation if you aren't careful to have resource budgets.
buf := strings.NewReader("\x9a\xff000")
nb := basicnode.Prototype.Any.NewBuilder()
err := Decode(nb, buf)
Require(t, err, ShouldEqual, ErrAllocationBudgetExceeded)
qt.Assert(t, err, qt.Equals, ErrAllocationBudgetExceeded)
})
t.Run("fuzz002", func(t *testing.T) {
// This fixture might cause an overly large allocation if you aren't careful to have resource budgets.
buf := strings.NewReader("\x9f\x9f\x9f\x9f\x9f\x9f\x9f\x9f\x9f\x9f\x9f\x9f\x9f\x9f\x9f\x9f\x9f\x9f\x9f\x9f\x9a\xff000")
nb := basicnode.Prototype.Any.NewBuilder()
err := Decode(nb, buf)
Require(t, err, ShouldEqual, ErrAllocationBudgetExceeded)
qt.Assert(t, err, qt.Equals, ErrAllocationBudgetExceeded)
})
t.Run("fuzz003", func(t *testing.T) {
// This fixture might cause an overly large allocation if you aren't careful to have resource budgets.
buf := strings.NewReader("\x9f\x9f\x9f\x9f\x9f\x9f\x9f\xbb00000000")
nb := basicnode.Prototype.Any.NewBuilder()
err := Decode(nb, buf)
Require(t, err, ShouldEqual, ErrAllocationBudgetExceeded)
qt.Assert(t, err, qt.Equals, ErrAllocationBudgetExceeded)
})
}
30 changes: 16 additions & 14 deletions codec/dagjson/roundtripBytes_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package dagjson
package dagjson_test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌


import (
"bytes"
"strings"
"testing"

. "github.com/warpfork/go-wish"
qt "github.com/frankban/quicktest"

"github.com/ipld/go-ipld-prime/codec/dagjson"
"github.com/ipld/go-ipld-prime/fluent"
"github.com/ipld/go-ipld-prime/node/basicnode"
nodetests "github.com/ipld/go-ipld-prime/node/tests"
)

var byteNode = fluent.MustBuildMap(basicnode.Prototype.Map, 4, func(na fluent.MapAssembler) {
Expand All @@ -24,16 +26,16 @@ var byteSerial = `{"bytes":{"/":{"bytes":"ZGVhZGJlZWY"}},"plain":"olde string"}`
func TestRoundtripBytes(t *testing.T) {
t.Run("encoding", func(t *testing.T) {
var buf bytes.Buffer
err := Encode(byteNode, &buf)
Require(t, err, ShouldEqual, nil)
Wish(t, buf.String(), ShouldEqual, byteSerial)
err := dagjson.Encode(byteNode, &buf)
qt.Assert(t, err, qt.IsNil)
qt.Check(t, buf.String(), qt.Equals, byteSerial)
})
t.Run("decoding", func(t *testing.T) {
buf := strings.NewReader(byteSerial)
nb := basicnode.Prototype.Map.NewBuilder()
err := Decode(nb, buf)
Require(t, err, ShouldEqual, nil)
Wish(t, nb.Build(), ShouldEqual, byteNodeSorted)
err := dagjson.Decode(nb, buf)
qt.Assert(t, err, qt.IsNil)
qt.Check(t, nb.Build(), nodetests.NodeContentEquals, byteNodeSorted)
})
}

Expand All @@ -47,15 +49,15 @@ var encapsulatedSerial = `{"/":{"bytes":{"/":{"bytes":"ZGVhZGJlZWY"}}}}`
func TestEncapsulatedBytes(t *testing.T) {
t.Run("encoding", func(t *testing.T) {
var buf bytes.Buffer
err := Encode(encapsulatedNode, &buf)
Require(t, err, ShouldEqual, nil)
Wish(t, buf.String(), ShouldEqual, encapsulatedSerial)
err := dagjson.Encode(encapsulatedNode, &buf)
qt.Assert(t, err, qt.IsNil)
qt.Check(t, buf.String(), qt.Equals, encapsulatedSerial)
})
t.Run("decoding", func(t *testing.T) {
buf := strings.NewReader(encapsulatedSerial)
nb := basicnode.Prototype.Map.NewBuilder()
err := Decode(nb, buf)
Require(t, err, ShouldEqual, nil)
Wish(t, nb.Build(), ShouldEqual, encapsulatedNode)
err := dagjson.Decode(nb, buf)
qt.Assert(t, err, qt.IsNil)
qt.Check(t, nb.Build(), nodetests.NodeContentEquals, encapsulatedNode)
})
}
22 changes: 12 additions & 10 deletions codec/dagjson/roundtripCidlink_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package dagjson
package dagjson_test

import (
"bytes"
"io"
"strings"
"testing"

. "github.com/warpfork/go-wish"
qt "github.com/frankban/quicktest"

cid "github.com/ipfs/go-cid"
"github.com/ipld/go-ipld-prime/codec/dagjson"
"github.com/ipld/go-ipld-prime/datamodel"
"github.com/ipld/go-ipld-prime/linking"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
"github.com/ipld/go-ipld-prime/node/basicnode"
nodetests "github.com/ipld/go-ipld-prime/node/tests"
)

func TestRoundtripCidlink(t *testing.T) {
Expand All @@ -33,11 +35,11 @@ func TestRoundtripCidlink(t *testing.T) {
}

lnk, err := lsys.Store(linking.LinkContext{}, lp, n)
Require(t, err, ShouldEqual, nil)
qt.Assert(t, err, qt.IsNil)

n2, err := lsys.Load(linking.LinkContext{}, lnk, basicnode.Prototype.Any)
Require(t, err, ShouldEqual, nil)
Wish(t, n2, ShouldEqual, nSorted)
qt.Assert(t, err, qt.IsNil)
qt.Check(t, n2, nodetests.NodeContentEquals, nSorted)
}

// Make sure that a map that *almost* looks like a link is handled safely.
Expand All @@ -58,11 +60,11 @@ func TestUnmarshalTrickyMapContainingLink(t *testing.T) {

// Unmarshal. Hopefully we get a map with a link in it.
nb := basicnode.Prototype.Any.NewBuilder()
err := Decode(nb, strings.NewReader(tricky))
Require(t, err, ShouldEqual, nil)
err := dagjson.Decode(nb, strings.NewReader(tricky))
qt.Assert(t, err, qt.IsNil)
n := nb.Build()
Wish(t, n.Kind(), ShouldEqual, datamodel.Kind_Map)
qt.Check(t, n.Kind(), qt.Equals, datamodel.Kind_Map)
n2, err := n.LookupByString("/")
Require(t, err, ShouldEqual, nil)
Wish(t, n2.Kind(), ShouldEqual, datamodel.Kind_Link)
qt.Assert(t, err, qt.IsNil)
qt.Check(t, n2.Kind(), qt.Equals, datamodel.Kind_Link)
}
30 changes: 16 additions & 14 deletions codec/dagjson/roundtrip_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package dagjson
package dagjson_test

import (
"bytes"
"strings"
"testing"

. "github.com/warpfork/go-wish"
qt "github.com/frankban/quicktest"

"github.com/ipld/go-ipld-prime/codec/dagjson"
"github.com/ipld/go-ipld-prime/fluent"
"github.com/ipld/go-ipld-prime/node/basicnode"
nodetests "github.com/ipld/go-ipld-prime/node/tests"
)

var n = fluent.MustBuildMap(basicnode.Prototype.Map, 4, func(na fluent.MapAssembler) {
Expand Down Expand Up @@ -48,16 +50,16 @@ var serial = `{"list":["three","four"],"map":{"one":1,"two":2},"nested":{"deeper
func TestRoundtrip(t *testing.T) {
t.Run("encoding", func(t *testing.T) {
var buf bytes.Buffer
err := Encode(n, &buf)
Require(t, err, ShouldEqual, nil)
Wish(t, buf.String(), ShouldEqual, serial)
err := dagjson.Encode(n, &buf)
qt.Assert(t, err, qt.IsNil)
qt.Check(t, buf.String(), qt.Equals, serial)
})
t.Run("decoding", func(t *testing.T) {
buf := strings.NewReader(serial)
nb := basicnode.Prototype.Map.NewBuilder()
err := Decode(nb, buf)
Require(t, err, ShouldEqual, nil)
Wish(t, nb.Build(), ShouldEqual, nSorted)
err := dagjson.Decode(nb, buf)
qt.Assert(t, err, qt.IsNil)
qt.Check(t, nb.Build(), nodetests.NodeContentEquals, nSorted)
})
}

Expand All @@ -67,15 +69,15 @@ func TestRoundtripScalar(t *testing.T) {
simple := nb.Build()
t.Run("encoding", func(t *testing.T) {
var buf bytes.Buffer
err := Encode(simple, &buf)
Require(t, err, ShouldEqual, nil)
Wish(t, buf.String(), ShouldEqual, `"applesauce"`)
err := dagjson.Encode(simple, &buf)
qt.Assert(t, err, qt.IsNil)
qt.Check(t, buf.String(), qt.Equals, `"applesauce"`)
})
t.Run("decoding", func(t *testing.T) {
buf := strings.NewReader(`"applesauce"`)
nb := basicnode.Prototype__String{}.NewBuilder()
err := Decode(nb, buf)
Require(t, err, ShouldEqual, nil)
Wish(t, nb.Build(), ShouldEqual, simple)
err := dagjson.Decode(nb, buf)
qt.Assert(t, err, qt.IsNil)
qt.Check(t, nb.Build(), nodetests.NodeContentEquals, simple)
})
}
3 changes: 2 additions & 1 deletion codec/raw/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ipld/go-ipld-prime/linking"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
"github.com/ipld/go-ipld-prime/node/basicnode"
nodetests "github.com/ipld/go-ipld-prime/node/tests"
)

var tests = []struct {
Expand Down Expand Up @@ -71,7 +72,7 @@ func TestRoundtripCidlink(t *testing.T) {

newNode, err := lsys.Load(linking.LinkContext{}, lnk, basicnode.Prototype.Any)
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, newNode, qt.DeepEquals, node)
qt.Assert(t, newNode, nodetests.NodeContentEquals, node)
}

// mustOnlyUseRead only exposes Read, hiding Bytes.
Expand Down
Loading