minor cleanups
This commit is contained in:
@@ -29,7 +29,7 @@ Verbatim copies of both licenses are included below:
|
||||
```
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
https://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
|
||||
@@ -130,12 +130,6 @@ func BenchmarkContainerSerialisation(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
func randBytes(n int) []byte {
|
||||
b := make([]byte, n)
|
||||
_, _ = rand.Read(b)
|
||||
return b
|
||||
}
|
||||
|
||||
func randDID() (crypto.PrivKey, did.DID) {
|
||||
privKey, _, err := crypto.GenerateEd25519Key(rand.Reader)
|
||||
if err != nil {
|
||||
@@ -150,7 +144,7 @@ func randDID() (crypto.PrivKey, did.DID) {
|
||||
|
||||
func randomString(length int) string {
|
||||
b := make([]byte, length/2+1)
|
||||
rand.Read(b)
|
||||
_, _ = rand.Read(b)
|
||||
return fmt.Sprintf("%x", b)[0:length]
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/ucan-wg/go-ucan/pkg/meta"
|
||||
"gotest.tools/v3/assert"
|
||||
|
||||
"github.com/ucan-wg/go-ucan/pkg/meta"
|
||||
)
|
||||
|
||||
func TestMeta_Add(t *testing.T) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package selector
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
@@ -11,7 +10,6 @@ import (
|
||||
"github.com/ipld/go-ipld-prime/datamodel"
|
||||
"github.com/ipld/go-ipld-prime/fluent/qp"
|
||||
"github.com/ipld/go-ipld-prime/node/basicnode"
|
||||
"github.com/ipld/go-ipld-prime/schema"
|
||||
)
|
||||
|
||||
// Selector describes a UCAN policy selector, as specified here:
|
||||
@@ -302,23 +300,6 @@ func kindString(n datamodel.Node) string {
|
||||
return n.Kind().String()
|
||||
}
|
||||
|
||||
func isMissing(err error) bool {
|
||||
if _, ok := err.(datamodel.ErrNotExists); ok {
|
||||
return true
|
||||
}
|
||||
if _, ok := err.(schema.ErrNoSuchField); ok {
|
||||
return true
|
||||
}
|
||||
if _, ok := err.(schema.ErrInvalidKey); ok {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func IsResolutionErr(err error) bool {
|
||||
return errors.As(err, &resolutionerr{})
|
||||
}
|
||||
|
||||
type resolutionerr struct {
|
||||
msg string
|
||||
at []string
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package selector
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -144,7 +145,6 @@ func TestSelect(t *testing.T) {
|
||||
fmt.Println(err)
|
||||
|
||||
require.ErrorAs(t, err, &resolutionerr{}, "error should be a resolution error")
|
||||
require.True(t, IsResolutionErr(err))
|
||||
})
|
||||
|
||||
t.Run("optional not exists", func(t *testing.T) {
|
||||
@@ -364,7 +364,7 @@ func FuzzParseAndSelect(f *testing.F) {
|
||||
|
||||
// look for panic()
|
||||
_, err = sel.Select(node)
|
||||
if err != nil && !IsResolutionErr(err) {
|
||||
if err != nil && !errors.As(err, &resolutionerr{}) {
|
||||
// not normal, we should only have resolution errors
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -101,7 +101,6 @@ func TestSupportedForms(t *testing.T) {
|
||||
// attempt to select
|
||||
res, err := sel.Select(makeNode(t, tc.Input))
|
||||
require.Error(t, err)
|
||||
require.True(t, selector.IsResolutionErr(err))
|
||||
require.Nil(t, res)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user