policy: fix some code style

This commit is contained in:
Michael Muré
2025-01-22 17:30:28 +01:00
parent 9c141029c3
commit 7ae65e7c8e
4 changed files with 24 additions and 24 deletions

View File

@@ -2,6 +2,7 @@ package policytest
import ( import (
"github.com/ipld/go-ipld-prime" "github.com/ipld/go-ipld-prime"
"github.com/ucan-wg/go-ucan/pkg/args" "github.com/ucan-wg/go-ucan/pkg/args"
"github.com/ucan-wg/go-ucan/pkg/policy" "github.com/ucan-wg/go-ucan/pkg/policy"
"github.com/ucan-wg/go-ucan/pkg/policy/literal" "github.com/ucan-wg/go-ucan/pkg/policy/literal"
@@ -10,9 +11,8 @@ import (
// EmptyPolicy provides a Policy with no statements. // EmptyPolicy provides a Policy with no statements.
var EmptyPolicy = policy.Policy{} var EmptyPolicy = policy.Policy{}
// ExampleValidationPolicy provides a instantiated SpecPolicy containing the // SpecPolicy provides a valid Policy containing the statements that are included
// statements that are included in the second code block of the [Validation] // in the second code block of the [Validation] section of the delegation specification.
// section of the delegation specification.
// //
// [Validation]: https://github.com/ucan-wg/delegation/tree/v1_ipld#validation // [Validation]: https://github.com/ucan-wg/delegation/tree/v1_ipld#validation
var SpecPolicy = policy.MustConstruct( var SpecPolicy = policy.MustConstruct(
@@ -24,8 +24,8 @@ var SpecPolicy = policy.MustConstruct(
// specification has been finished/merged. // specification has been finished/merged.
// SpecValidArguments provides valid, instantiated Arguments containing // SpecValidArguments provides valid, instantiated Arguments containing
// the key/value pairs that are included in portion of the the second code // the key/value pairs that are included in portion of the second code block
// block of the [Validation] section of the delegation specification. // of the [Validation] section of the delegation specification.
// //
// [Validation]: https://github.com/ucan-wg/delegation/tree/v1_ipld#validation // [Validation]: https://github.com/ucan-wg/delegation/tree/v1_ipld#validation
var SpecValidArguments = args.NewBuilder(). var SpecValidArguments = args.NewBuilder().
@@ -41,8 +41,8 @@ var SpecValidArguments = args.NewBuilder().
var specValidArgumentsIPLD = mustIPLD(SpecValidArguments) var specValidArgumentsIPLD = mustIPLD(SpecValidArguments)
// SpecInvalidArguments provides invalid, instantiated Arguments containing // SpecInvalidArguments provides invalid, instantiated Arguments containing
// the key/value pairs that are included in portion of the the second code // the key/value pairs that are included in portion of the second code block
// block of the [Validation] section of the delegation specification. // of the [Validation] section of the delegation specification.
// //
// [Validation]: https://github.com/ucan-wg/delegation/tree/v1_ipld#validation // [Validation]: https://github.com/ucan-wg/delegation/tree/v1_ipld#validation
var SpecInvalidArguments = args.NewBuilder(). var SpecInvalidArguments = args.NewBuilder().

View File

@@ -173,37 +173,37 @@ func tokenize(str string) []string {
return toks return toks
} }
type parseerr struct { type parseErr struct {
msg string msg string
src string src string
col int col int
tok string tok string
} }
func (p parseerr) Name() string { func (p parseErr) Name() string {
return "ParseError" return "ParseError"
} }
func (p parseerr) Message() string { func (p parseErr) Message() string {
return p.msg return p.msg
} }
func (p parseerr) Column() int { func (p parseErr) Column() int {
return p.col return p.col
} }
func (p parseerr) Error() string { func (p parseErr) Error() string {
return p.msg return p.msg
} }
func (p parseerr) Source() string { func (p parseErr) Source() string {
return p.src return p.src
} }
func (p parseerr) Token() string { func (p parseErr) Token() string {
return p.tok return p.tok
} }
func newParseError(message string, source string, column int, token string) error { func newParseError(message string, source string, column int, token string) error {
return parseerr{message, source, column, token} return parseErr{message, source, column, token}
} }

View File

@@ -19,7 +19,7 @@ type Selector []segment
// Select perform the selection described by the selector on the input IPLD DAG. // Select perform the selection described by the selector on the input IPLD DAG.
// Select can return: // Select can return:
// - exactly one matched IPLD node // - exactly one matched IPLD node
// - a resolutionerr error if not being able to resolve to a node // - a resolutionErr error if not being able to resolve to a node
// - nil and no errors, if the selector couldn't match on an optional segment (with ?). // - nil and no errors, if the selector couldn't match on an optional segment (with ?).
func (s Selector) Select(subject ipld.Node) (ipld.Node, error) { func (s Selector) Select(subject ipld.Node) (ipld.Node, error) {
return resolve(s, subject, nil) return resolve(s, subject, nil)
@@ -316,27 +316,27 @@ func kindString(n datamodel.Node) string {
return n.Kind().String() return n.Kind().String()
} }
type resolutionerr struct { type resolutionErr struct {
msg string msg string
at []string at []string
} }
func (r resolutionerr) Name() string { func (r resolutionErr) Name() string {
return "ResolutionError" return "ResolutionError"
} }
func (r resolutionerr) Message() string { func (r resolutionErr) Message() string {
return fmt.Sprintf("can not resolve path: .%s", strings.Join(r.at, ".")) return fmt.Sprintf("can not resolve path: .%s", strings.Join(r.at, "."))
} }
func (r resolutionerr) At() []string { func (r resolutionErr) At() []string {
return r.at return r.at
} }
func (r resolutionerr) Error() string { func (r resolutionErr) Error() string {
return r.Message() return r.Message()
} }
func newResolutionError(message string, at []string) error { func newResolutionError(message string, at []string) error {
return resolutionerr{message, at} return resolutionErr{message, at}
} }

View File

@@ -133,7 +133,7 @@ func TestSelect(t *testing.T) {
require.Error(t, err) require.Error(t, err)
require.Empty(t, res) require.Empty(t, res)
require.ErrorAs(t, err, &resolutionerr{}, "error should be a resolution error") require.ErrorAs(t, err, &resolutionErr{}, "error should be a resolution error")
}) })
t.Run("optional not exists", func(t *testing.T) { t.Run("optional not exists", func(t *testing.T) {
@@ -351,7 +351,7 @@ func FuzzParseAndSelect(f *testing.F) {
// look for panic() // look for panic()
_, err = sel.Select(node) _, err = sel.Select(node)
if err != nil && !errors.As(err, &resolutionerr{}) { if err != nil && !errors.As(err, &resolutionErr{}) {
// not normal, we should only have resolution errors // not normal, we should only have resolution errors
t.Fatal(err) t.Fatal(err)
} }