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 node package tests to quicktest #289

Merged
merged 1 commit into from
Nov 10, 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
48 changes: 24 additions & 24 deletions node/tests/listSpecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package tests
import (
"testing"

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

"github.com/ipld/go-ipld-prime/datamodel"
"github.com/ipld/go-ipld-prime/fluent"
Expand All @@ -18,46 +18,46 @@ func SpecTestListString(t *testing.T, np datamodel.NodePrototype) {
la.AssembleValue().AssignString("three")
})
t.Run("reads back out", func(t *testing.T) {
Wish(t, n.Length(), ShouldEqual, int64(3))
qt.Check(t, n.Length(), qt.Equals, int64(3))

v, err := n.LookupByIndex(0)
Wish(t, err, ShouldEqual, nil)
Wish(t, must.String(v), ShouldEqual, "one")
qt.Check(t, err, qt.IsNil)
qt.Check(t, must.String(v), qt.Equals, "one")

v, err = n.LookupByIndex(1)
Wish(t, err, ShouldEqual, nil)
Wish(t, must.String(v), ShouldEqual, "two")
qt.Check(t, err, qt.IsNil)
qt.Check(t, must.String(v), qt.Equals, "two")

v, err = n.LookupByIndex(2)
Wish(t, err, ShouldEqual, nil)
Wish(t, must.String(v), ShouldEqual, "three")
qt.Check(t, err, qt.IsNil)
qt.Check(t, must.String(v), qt.Equals, "three")
})
t.Run("reads via iteration", func(t *testing.T) {
itr := n.ListIterator()

Wish(t, itr.Done(), ShouldEqual, false)
qt.Check(t, itr.Done(), qt.IsFalse)
idx, v, err := itr.Next()
Wish(t, err, ShouldEqual, nil)
Wish(t, idx, ShouldEqual, int64(0))
Wish(t, must.String(v), ShouldEqual, "one")
qt.Check(t, err, qt.IsNil)
qt.Check(t, idx, qt.Equals, int64(0))
qt.Check(t, must.String(v), qt.Equals, "one")

Wish(t, itr.Done(), ShouldEqual, false)
qt.Check(t, itr.Done(), qt.IsFalse)
idx, v, err = itr.Next()
Wish(t, err, ShouldEqual, nil)
Wish(t, idx, ShouldEqual, int64(1))
Wish(t, must.String(v), ShouldEqual, "two")
qt.Check(t, err, qt.IsNil)
qt.Check(t, idx, qt.Equals, int64(1))
qt.Check(t, must.String(v), qt.Equals, "two")

Wish(t, itr.Done(), ShouldEqual, false)
qt.Check(t, itr.Done(), qt.IsFalse)
idx, v, err = itr.Next()
Wish(t, err, ShouldEqual, nil)
Wish(t, idx, ShouldEqual, int64(2))
Wish(t, must.String(v), ShouldEqual, "three")
qt.Check(t, err, qt.IsNil)
qt.Check(t, idx, qt.Equals, int64(2))
qt.Check(t, must.String(v), qt.Equals, "three")

Wish(t, itr.Done(), ShouldEqual, true)
qt.Check(t, itr.Done(), qt.IsTrue)
idx, v, err = itr.Next()
Wish(t, err, ShouldEqual, datamodel.ErrIteratorOverread{})
Wish(t, idx, ShouldEqual, int64(-1))
Wish(t, v, ShouldEqual, nil)
qt.Check(t, err, qt.Equals, datamodel.ErrIteratorOverread{})
qt.Check(t, idx, qt.Equals, int64(-1))
qt.Check(t, v, qt.IsNil)
})
})
}
110 changes: 55 additions & 55 deletions node/tests/mapSpecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package tests
import (
"testing"

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

"github.com/ipld/go-ipld-prime/datamodel"
"github.com/ipld/go-ipld-prime/must"
Expand All @@ -13,70 +13,70 @@ func SpecTestMapStrInt(t *testing.T, np datamodel.NodePrototype) {
t.Run("map<str,int>, 3 entries", func(t *testing.T) {
n := buildMapStrIntN3(np)
t.Run("reads back out", func(t *testing.T) {
Wish(t, n.Length(), ShouldEqual, int64(3))
qt.Check(t, n.Length(), qt.Equals, int64(3))

v, err := n.LookupByString("whee")
Wish(t, err, ShouldEqual, nil)
qt.Check(t, err, qt.IsNil)
v2, err := v.AsInt()
Wish(t, err, ShouldEqual, nil)
Wish(t, v2, ShouldEqual, int64(1))
qt.Check(t, err, qt.IsNil)
qt.Check(t, v2, qt.Equals, int64(1))

v, err = n.LookupByString("waga")
Wish(t, err, ShouldEqual, nil)
qt.Check(t, err, qt.IsNil)
v2, err = v.AsInt()
Wish(t, err, ShouldEqual, nil)
Wish(t, v2, ShouldEqual, int64(3))
qt.Check(t, err, qt.IsNil)
qt.Check(t, v2, qt.Equals, int64(3))

v, err = n.LookupByString("woot")
Wish(t, err, ShouldEqual, nil)
qt.Check(t, err, qt.IsNil)
v2, err = v.AsInt()
Wish(t, err, ShouldEqual, nil)
Wish(t, v2, ShouldEqual, int64(2))
qt.Check(t, err, qt.IsNil)
qt.Check(t, v2, qt.Equals, int64(2))
})
t.Run("reads via iteration", func(t *testing.T) {
itr := n.MapIterator()

Wish(t, itr.Done(), ShouldEqual, false)
qt.Check(t, itr.Done(), qt.IsFalse)
k, v, err := itr.Next()
Wish(t, err, ShouldEqual, nil)
qt.Check(t, err, qt.IsNil)
k2, err := k.AsString()
Wish(t, err, ShouldEqual, nil)
Wish(t, k2, ShouldEqual, "whee")
qt.Check(t, err, qt.IsNil)
qt.Check(t, k2, qt.Equals, "whee")
v2, err := v.AsInt()
Wish(t, err, ShouldEqual, nil)
Wish(t, v2, ShouldEqual, int64(1))
qt.Check(t, err, qt.IsNil)
qt.Check(t, v2, qt.Equals, int64(1))

Wish(t, itr.Done(), ShouldEqual, false)
qt.Check(t, itr.Done(), qt.IsFalse)
k, v, err = itr.Next()
Wish(t, err, ShouldEqual, nil)
qt.Check(t, err, qt.IsNil)
k2, err = k.AsString()
Wish(t, err, ShouldEqual, nil)
Wish(t, k2, ShouldEqual, "woot")
qt.Check(t, err, qt.IsNil)
qt.Check(t, k2, qt.Equals, "woot")
v2, err = v.AsInt()
Wish(t, err, ShouldEqual, nil)
Wish(t, v2, ShouldEqual, int64(2))
qt.Check(t, err, qt.IsNil)
qt.Check(t, v2, qt.Equals, int64(2))

Wish(t, itr.Done(), ShouldEqual, false)
qt.Check(t, itr.Done(), qt.IsFalse)
k, v, err = itr.Next()
Wish(t, err, ShouldEqual, nil)
qt.Check(t, err, qt.IsNil)
k2, err = k.AsString()
Wish(t, err, ShouldEqual, nil)
Wish(t, k2, ShouldEqual, "waga")
qt.Check(t, err, qt.IsNil)
qt.Check(t, k2, qt.Equals, "waga")
v2, err = v.AsInt()
Wish(t, err, ShouldEqual, nil)
Wish(t, v2, ShouldEqual, int64(3))
qt.Check(t, err, qt.IsNil)
qt.Check(t, v2, qt.Equals, int64(3))

Wish(t, itr.Done(), ShouldEqual, true)
qt.Check(t, itr.Done(), qt.IsTrue)
k, v, err = itr.Next()
Wish(t, err, ShouldEqual, datamodel.ErrIteratorOverread{})
Wish(t, k, ShouldEqual, nil)
Wish(t, v, ShouldEqual, nil)
qt.Check(t, err, qt.Equals, datamodel.ErrIteratorOverread{})
qt.Check(t, k, qt.IsNil)
qt.Check(t, v, qt.IsNil)
})
t.Run("reads for absent keys error sensibly", func(t *testing.T) {
v, err := n.LookupByString("nope")
Wish(t, err, ShouldBeSameTypeAs, datamodel.ErrNotExists{})
Wish(t, err.Error(), ShouldEqual, `key not found: "nope"`)
Wish(t, v, ShouldEqual, nil)
qt.Check(t, err, qt.ErrorAs, &datamodel.ErrNotExists{})
qt.Check(t, err, qt.ErrorMatches, `key not found: "nope"`)
qt.Check(t, v, qt.IsNil)
})
})
t.Run("repeated key should error", func(t *testing.T) {
Expand All @@ -92,7 +92,7 @@ func SpecTestMapStrInt(t *testing.T, np datamodel.NodePrototype) {
panic(err)
}
if err := ma.AssembleKey().AssignString("whee"); err != nil {
Wish(t, err, ShouldBeSameTypeAs, datamodel.ErrRepeatedMapKey{})
qt.Check(t, err, qt.ErrorAs, &datamodel.ErrRepeatedMapKey{})
// No string assertion at present -- how that should be presented for typed stuff is unsettled
// (and if it's clever, it'll differ from untyped, which will mean no assertion possible!).
}
Expand Down Expand Up @@ -122,14 +122,14 @@ func SpecTestMapStrInt(t *testing.T, np datamodel.NodePrototype) {
}()

// ... and neither of these should've had visible effects!
Wish(t, ma.Finish(), ShouldEqual, nil)
qt.Check(t, ma.Finish(), qt.IsNil)
n := nb.Build()
Wish(t, n.Length(), ShouldEqual, int64(1))
qt.Check(t, n.Length(), qt.Equals, int64(1))
v, err := n.LookupByString("whee")
Wish(t, err, ShouldEqual, nil)
qt.Check(t, err, qt.IsNil)
v2, err := v.AsInt()
Wish(t, err, ShouldEqual, nil)
Wish(t, v2, ShouldEqual, int64(1))
qt.Check(t, err, qt.IsNil)
qt.Check(t, v2, qt.Equals, int64(1))
})
t.Run("builder reset works", func(t *testing.T) {
// TODO
Expand Down Expand Up @@ -169,20 +169,20 @@ func SpecTestMapStrMapStrInt(t *testing.T, np datamodel.NodePrototype) {
n := nb.Build()

t.Run("reads back out", func(t *testing.T) {
Wish(t, n.Length(), ShouldEqual, int64(3))
qt.Check(t, n.Length(), qt.Equals, int64(3))

v, err := n.LookupByString("woot")
Wish(t, err, ShouldEqual, nil)
qt.Check(t, err, qt.IsNil)
v2, err := v.LookupByString("m2k1")
Wish(t, err, ShouldEqual, nil)
qt.Check(t, err, qt.IsNil)
v3, err := v2.AsInt()
Wish(t, err, ShouldEqual, nil)
Wish(t, v3, ShouldEqual, int64(3))
qt.Check(t, err, qt.IsNil)
qt.Check(t, v3, qt.Equals, int64(3))
v2, err = v.LookupByString("m2k2")
Wish(t, err, ShouldEqual, nil)
qt.Check(t, err, qt.IsNil)
v3, err = v2.AsInt()
Wish(t, err, ShouldEqual, nil)
Wish(t, v3, ShouldEqual, int64(4))
qt.Check(t, err, qt.IsNil)
qt.Check(t, v3, qt.Equals, int64(4))
})
})
}
Expand Down Expand Up @@ -214,15 +214,15 @@ func SpecTestMapStrListStr(t *testing.T, np datamodel.NodePrototype) {
n := nb.Build()

t.Run("reads back out", func(t *testing.T) {
Wish(t, n.Length(), ShouldEqual, int64(3))
qt.Check(t, n.Length(), qt.Equals, int64(3))

v, err := n.LookupByString("qwer")
Wish(t, err, ShouldEqual, nil)
qt.Check(t, err, qt.IsNil)
v2, err := v.LookupByIndex(1)
Wish(t, err, ShouldEqual, nil)
qt.Check(t, err, qt.IsNil)
v3, err := v2.AsString()
Wish(t, err, ShouldEqual, nil)
Wish(t, v3, ShouldEqual, "twentytwo")
qt.Check(t, err, qt.IsNil)
qt.Check(t, v3, qt.Equals, "twentytwo")
})
})
}
20 changes: 10 additions & 10 deletions node/tests/schemaLinks.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

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

"github.com/ipfs/go-cid"
"github.com/ipld/go-ipld-prime/codec/dagjson"
Expand Down Expand Up @@ -92,7 +92,7 @@ func SchemaTestLinks(t *testing.T, engine Engine) {
ssb.ExploreAll(ssb.ExploreRecursiveEdge()),
))
s, err := ss.Selector()
Wish(t, err, ShouldEqual, nil)
qt.Check(t, err, qt.IsNil)

var order int
lsys := cidlink.DefaultLinkSystem()
Expand All @@ -113,26 +113,26 @@ func SchemaTestLinks(t *testing.T, engine Engine) {
fmt.Printf("Walked %d: %v\n", order, buf.String())
switch order {
case 0: // root
Wish(t, n.Prototype(), ShouldEqual, engine.PrototypeByName("LinkStruct"))
qt.Check(t, n.Prototype(), qt.Equals, engine.PrototypeByName("LinkStruct"))
case 1: // from an &Any
Wish(t, n.Prototype(), ShouldEqual, basicnode.Prototype__String{})
qt.Check(t, n.Prototype(), qt.Equals, basicnode.Prototype__String{})
case 2: // &Int
Wish(t, n.Prototype(), ShouldEqual, engine.PrototypeByName("Int"))
qt.Check(t, n.Prototype(), qt.Equals, engine.PrototypeByName("Int"))
case 3: // &String
Wish(t, n.Prototype(), ShouldEqual, engine.PrototypeByName("String"))
qt.Check(t, n.Prototype(), qt.Equals, engine.PrototypeByName("String"))
case 4: // &ListOfStrings
Wish(t, n.Prototype(), ShouldEqual, engine.PrototypeByName("ListOfStrings"))
qt.Check(t, n.Prototype(), qt.Equals, engine.PrototypeByName("ListOfStrings"))
case 5:
fallthrough
case 6:
fallthrough
case 7:
Wish(t, n.Prototype(), ShouldEqual, engine.PrototypeByName("String"))
qt.Check(t, n.Prototype(), qt.Equals, engine.PrototypeByName("String"))
}
order++
return nil
})
Wish(t, err, ShouldEqual, nil)
Wish(t, order, ShouldEqual, 8)
qt.Check(t, err, qt.IsNil)
qt.Check(t, order, qt.Equals, 8)
})
}
Loading