From 6edc4f7b1b646b382007bd0353d526d80c31b1e0 Mon Sep 17 00:00:00 2001 From: Jay Pipes Date: Tue, 25 Jun 2024 10:23:44 -0400 Subject: [PATCH] consolidate types/, result/ and errors/ into api/ simplify the top-level packages by combining types/, result/ and errors/ into a single `api/` package. Signed-off-by: Jay Pipes --- {types => api}/assertions.go | 2 +- {types => api}/defaults.go | 2 +- errors/parse.go => api/error.go | 104 +++++++++++++- errors/parse_test.go => api/error_test.go | 8 +- {types => api}/evaluable.go | 6 +- {types => api}/fixture.go | 2 +- {types => api}/flexstrings.go | 8 +- {types => api}/flexstrings_test.go | 11 +- {types => api}/plugin.go | 2 +- {result => api}/result.go | 6 +- {types => api}/retry.go | 2 +- {types => api}/spec.go | 25 ++-- {types => api}/timeout.go | 2 +- {types => api}/wait.go | 2 +- assertion/json/errors.go | 24 ++-- assertion/json/json.go | 23 ++-- assertion/json/json_test.go | 6 +- context/context.go | 11 +- context/context_test.go | 23 ++-- context/getter.go | 18 +-- context/timeout.go | 4 +- errors/failure.go | 94 ------------- errors/runtime.go | 28 ---- fixture/generic.go | 4 +- fixture/json/json.go | 7 +- fixture/json/json_test.go | 8 +- plugin/exec/action.go | 6 +- plugin/exec/assertions.go | 25 ++-- plugin/exec/defaults.go | 8 +- plugin/exec/errors.go | 8 +- plugin/exec/eval.go | 11 +- plugin/exec/parse.go | 51 ++++--- plugin/exec/parse_test.go | 11 +- plugin/exec/plugin.go | 14 +- plugin/exec/spec.go | 12 +- plugin/registry.go | 18 +-- plugin/registry_test.go | 23 ++-- porcelain.go | 6 +- porcelain_test.go | 4 +- scenario/defaults.go | 26 ++-- scenario/parse.go | 45 +++--- scenario/parse_test.go | 49 ++++--- scenario/run.go | 42 +++--- scenario/run_test.go | 6 +- scenario/scenario.go | 8 +- scenario/stub_plugins_test.go | 158 +++++++++++----------- 46 files changed, 463 insertions(+), 500 deletions(-) rename {types => api}/assertions.go (97%) rename {types => api}/defaults.go (96%) rename errors/parse.go => api/error.go (64%) rename errors/parse_test.go => api/error_test.go (72%) rename {types => api}/evaluable.go (89%) rename {types => api}/fixture.go (97%) rename {types => api}/flexstrings.go (85%) rename {types => api}/flexstrings_test.go (84%) rename {types => api}/plugin.go (98%) rename {result => api}/result.go (96%) rename {types => api}/retry.go (99%) rename {types => api}/spec.go (87%) rename {types => api}/timeout.go (98%) rename {types => api}/wait.go (98%) delete mode 100644 errors/failure.go delete mode 100644 errors/runtime.go diff --git a/types/assertions.go b/api/assertions.go similarity index 97% rename from types/assertions.go rename to api/assertions.go index 510d436..831ead1 100644 --- a/types/assertions.go +++ b/api/assertions.go @@ -2,7 +2,7 @@ // // See the COPYING file in the root project directory for full text. -package types +package api import "context" diff --git a/types/defaults.go b/api/defaults.go similarity index 96% rename from types/defaults.go rename to api/defaults.go index 3152d3c..6567c6c 100644 --- a/types/defaults.go +++ b/api/defaults.go @@ -2,7 +2,7 @@ // // See the COPYING file in the root project directory for full text. -package types +package api // Defaults are a collection of default configuration values type Defaults map[string]interface{} diff --git a/errors/parse.go b/api/error.go similarity index 64% rename from errors/parse.go rename to api/error.go index 3761389..4a1c7c0 100644 --- a/errors/parse.go +++ b/api/error.go @@ -2,7 +2,7 @@ // // See the COPYING file in the root project directory for full text. -package errors +package api import ( "errors" @@ -11,6 +11,90 @@ import ( "gopkg.in/yaml.v3" ) +var ( + // ErrFailure is the base error class for all errors that represent failed + // assertions when evaluating a test. + ErrFailure = errors.New("assertion failed") + // ErrTimeoutExceeded is an ErrFailure when a test's execution exceeds a + // timeout length. + ErrTimeoutExceeded = fmt.Errorf("%s: timeout exceeded", ErrFailure) + // ErrNotEqual is an ErrFailure when an expected thing doesn't equal an + // observed thing. + ErrNotEqual = fmt.Errorf("%w: not equal", ErrFailure) + // ErrIn is an ErrFailure when a thing unexpectedly appears in an + // container. + ErrIn = fmt.Errorf("%w: in", ErrFailure) + // ErrNotIn is an ErrFailure when an expected thing doesn't appear in an + // expected container. + ErrNotIn = fmt.Errorf("%w: not in", ErrFailure) + // ErrNoneIn is an ErrFailure when none of a list of elements appears in an + // expected container. + ErrNoneIn = fmt.Errorf("%w: none in", ErrFailure) + // ErrUnexpectedError is an ErrFailure when an unexpected error has + // occurred. + ErrUnexpectedError = fmt.Errorf("%w: unexpected error", ErrFailure) +) + +// TimeoutExceeded returns an ErrTimeoutExceeded when a test's execution +// exceeds a timeout length. The optional failure parameter indicates a failed +// assertion that occurred before a timeout was reached. +func TimeoutExceeded(duration string, failure error) error { + if failure != nil { + return fmt.Errorf( + "%w: timed out waiting for assertion to succeed (%s)", + failure, duration, + ) + } + return fmt.Errorf("%s (%s)", ErrTimeoutExceeded, duration) +} + +// NotEqualLength returns an ErrNotEqual when an expected length doesn't +// equal an observed length. +func NotEqualLength(exp, got int) error { + return fmt.Errorf( + "%w: expected length of %d but got %d", + ErrNotEqual, exp, got, + ) +} + +// NotEqual returns an ErrNotEqual when an expected thing doesn't equal an +// observed thing. +func NotEqual(exp, got interface{}) error { + return fmt.Errorf("%w: expected %v but got %v", ErrNotEqual, exp, got) +} + +// In returns an ErrIn when a thing unexpectedly appears in a container. +func In(element, container interface{}) error { + return fmt.Errorf( + "%w: expected %v not to contain %v", + ErrIn, container, element, + ) +} + +// NotIn returns an ErrNotIn when an expected thing doesn't appear in an +// expected container. +func NotIn(element, container interface{}) error { + return fmt.Errorf( + "%w: expected %v to contain %v", + ErrNotIn, container, element, + ) +} + +// NoneIn returns an ErrNoneIn when none of a list of elements appears in an +// expected container. +func NoneIn(elements, container interface{}) error { + return fmt.Errorf( + "%w: expected %v to contain one of %v", + ErrNoneIn, container, elements, + ) +} + +// UnexpectedError returns an ErrUnexpectedError when a supplied error is not +// expected. +func UnexpectedError(err error) error { + return fmt.Errorf("%w: %s", ErrUnexpectedError, err) +} + var ( // ErrUnknownSourceType indicates that a From() function was called with an // unknown source parameter type. @@ -199,3 +283,21 @@ func FileNotFound(path string, node *yaml.Node) error { ErrFileNotFound, path, node.Line, node.Column, ) } + +var ( + // RuntimeError is the base error class for all errors occurring during + // runtime (and not during the parsing of a scenario or spec) + RuntimeError = errors.New("runtime error") + // ErrRequiredFixture is returned when a required fixture has not + // been registered with the context. + ErrRequiredFixture = fmt.Errorf( + "%w: required fixture missing", + RuntimeError, + ) +) + +// RequiredFixtureMissing returns an ErrRequiredFixture with the supplied +// fixture name +func RequiredFixtureMissing(name string) error { + return fmt.Errorf("%w: %s", ErrRequiredFixture, name) +} diff --git a/errors/parse_test.go b/api/error_test.go similarity index 72% rename from errors/parse_test.go rename to api/error_test.go index 15452cc..69e2afd 100644 --- a/errors/parse_test.go +++ b/api/error_test.go @@ -2,22 +2,22 @@ // // See the COPYING file in the root project directory for full text. -package errors_test +package api_test import ( "testing" - gdterrors "github.com/gdt-dev/gdt/errors" + "github.com/gdt-dev/gdt/api" "github.com/stretchr/testify/assert" ) func TestUnknownSourceType(t *testing.T) { assert := assert.New(t) - err := gdterrors.UnknownSourceType(1) + err := api.UnknownSourceType(1) assert.ErrorContains(err, "int") source := []string{"foo", "bar"} - err = gdterrors.UnknownSourceType(source) + err = api.UnknownSourceType(source) assert.ErrorContains(err, "[]string") } diff --git a/types/evaluable.go b/api/evaluable.go similarity index 89% rename from types/evaluable.go rename to api/evaluable.go index 4288f29..b1cfba6 100644 --- a/types/evaluable.go +++ b/api/evaluable.go @@ -2,12 +2,10 @@ // // See the COPYING file in the root project directory for full text. -package types +package api import ( "context" - - "github.com/gdt-dev/gdt/result" ) // Evaluable represents individual test units in a Scenario @@ -18,7 +16,7 @@ type Evaluable interface { // // Errors returned by Eval() are **RuntimeErrors**, not failures in // assertions. - Eval(context.Context) (*result.Result, error) + Eval(context.Context) (*Result, error) // SetBase sets the Evaluable's base Spec SetBase(Spec) // Base returns the Evaluable's base Spec diff --git a/types/fixture.go b/api/fixture.go similarity index 97% rename from types/fixture.go rename to api/fixture.go index 8cb4b7a..5f0789a 100644 --- a/types/fixture.go +++ b/api/fixture.go @@ -2,7 +2,7 @@ // // See the COPYING file in the root project directory for full text. -package types +package api import "context" diff --git a/types/flexstrings.go b/api/flexstrings.go similarity index 85% rename from types/flexstrings.go rename to api/flexstrings.go index 5689b84..7d681da 100644 --- a/types/flexstrings.go +++ b/api/flexstrings.go @@ -2,12 +2,10 @@ // // See the COPYING file in the root project directory for full text. -package types +package api import ( "gopkg.in/yaml.v3" - - gdterrors "github.com/gdt-dev/gdt/errors" ) // FlexStrings is a struct used to parse an interface{} that can be either a @@ -25,7 +23,7 @@ func (f *FlexStrings) Values() []string { // FlexStrings can be either a string or a slice of strings. func (f *FlexStrings) UnmarshalYAML(node *yaml.Node) error { if node.Kind != yaml.ScalarNode && node.Kind != yaml.SequenceNode { - return gdterrors.ExpectedScalarOrSequenceAt(node) + return ExpectedScalarOrSequenceAt(node) } var single string if err := node.Decode(&single); err == nil { @@ -37,5 +35,5 @@ func (f *FlexStrings) UnmarshalYAML(node *yaml.Node) error { f.values = many return nil } - return gdterrors.ExpectedScalarOrSequenceAt(node) + return ExpectedScalarOrSequenceAt(node) } diff --git a/types/flexstrings_test.go b/api/flexstrings_test.go similarity index 84% rename from types/flexstrings_test.go rename to api/flexstrings_test.go index ce53790..e8c64d3 100644 --- a/types/flexstrings_test.go +++ b/api/flexstrings_test.go @@ -2,24 +2,23 @@ // // See the COPYING file in the root project directory for full text. -package types_test +package api_test import ( "testing" - gdterrors "github.com/gdt-dev/gdt/errors" - gdttypes "github.com/gdt-dev/gdt/types" + "github.com/gdt-dev/gdt/api" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gopkg.in/yaml.v3" ) type foo struct { - Foo gdttypes.FlexStrings `yaml:"foo"` + Foo api.FlexStrings `yaml:"foo"` } type foop struct { - Foo *gdttypes.FlexStrings `yaml:"foo"` + Foo *api.FlexStrings `yaml:"foo"` } func TestFlexStringsError(t *testing.T) { @@ -31,7 +30,7 @@ func TestFlexStringsError(t *testing.T) { err := yaml.Unmarshal(contents, &f) require.NotNil(err) - assert.ErrorIs(err, gdterrors.ErrExpectedScalarOrSequence) + assert.ErrorIs(err, api.ErrExpectedScalarOrSequence) } func TestFlexStrings(t *testing.T) { diff --git a/types/plugin.go b/api/plugin.go similarity index 98% rename from types/plugin.go rename to api/plugin.go index 151d7b5..b0b3e21 100644 --- a/types/plugin.go +++ b/api/plugin.go @@ -2,7 +2,7 @@ // // See the COPYING file in the root project directory for full text. -package types +package api import "gopkg.in/yaml.v3" diff --git a/result/result.go b/api/result.go similarity index 96% rename from result/result.go rename to api/result.go index 8182460..b9741e3 100644 --- a/result/result.go +++ b/api/result.go @@ -2,7 +2,7 @@ // // See the COPYING file in the root project directory for full text. -package result +package api // Result is returned from a `Evaluable.Eval` execution. It serves two // purposes: @@ -80,8 +80,8 @@ func WithFailures(failures ...error) ResultModifier { } } -// New returns a new Result -func New(mods ...ResultModifier) *Result { +// NewResult returns a new Result +func NewResult(mods ...ResultModifier) *Result { r := &Result{} for _, mod := range mods { mod(r) diff --git a/types/retry.go b/api/retry.go similarity index 99% rename from types/retry.go rename to api/retry.go index d7b46e0..a6b717a 100644 --- a/types/retry.go +++ b/api/retry.go @@ -2,7 +2,7 @@ // // See the COPYING file in the root project directory for full text. -package types +package api import ( "time" diff --git a/types/spec.go b/api/spec.go similarity index 87% rename from types/spec.go rename to api/spec.go index ebd6762..9a2bdc0 100644 --- a/types/spec.go +++ b/api/spec.go @@ -2,14 +2,13 @@ // // See the COPYING file in the root project directory for full text. -package types +package api import ( "strconv" "strings" "time" - "github.com/gdt-dev/gdt/errors" "gopkg.in/yaml.v3" ) @@ -82,26 +81,26 @@ func slugify(s string) string { // the associated struct field from that value node. func (s *Spec) UnmarshalYAML(node *yaml.Node) error { if node.Kind != yaml.MappingNode { - return errors.ExpectedMapAt(node) + return ExpectedMapAt(node) } // maps/structs are stored in a top-level Node.Content field which is a // concatenated slice of Node pointers in pairs of key/values. for i := 0; i < len(node.Content); i += 2 { keyNode := node.Content[i] if keyNode.Kind != yaml.ScalarNode { - return errors.ExpectedScalarAt(keyNode) + return ExpectedScalarAt(keyNode) } key := keyNode.Value valNode := node.Content[i+1] switch key { case "name": if valNode.Kind != yaml.ScalarNode { - return errors.ExpectedScalarAt(valNode) + return ExpectedScalarAt(valNode) } s.Name = valNode.Value case "description": if valNode.Kind != yaml.ScalarNode { - return errors.ExpectedScalarAt(valNode) + return ExpectedScalarAt(valNode) } s.Description = valNode.Value case "timeout": @@ -110,7 +109,7 @@ func (s *Spec) UnmarshalYAML(node *yaml.Node) error { case yaml.MappingNode: // We support the old-style timeout:after if err := valNode.Decode(&to); err != nil { - return errors.ExpectedTimeoutAt(valNode) + return ExpectedTimeoutAt(valNode) } case yaml.ScalarNode: // We also support a straight string duration @@ -118,7 +117,7 @@ func (s *Spec) UnmarshalYAML(node *yaml.Node) error { After: valNode.Value, } default: - return errors.ExpectedScalarOrMapAt(valNode) + return ExpectedScalarOrMapAt(valNode) } _, err := time.ParseDuration(to.After) if err != nil { @@ -127,11 +126,11 @@ func (s *Spec) UnmarshalYAML(node *yaml.Node) error { s.Timeout = to case "wait": if valNode.Kind != yaml.MappingNode { - return errors.ExpectedMapAt(valNode) + return ExpectedMapAt(valNode) } var w *Wait if err := valNode.Decode(&w); err != nil { - return errors.ExpectedWaitAt(valNode) + return ExpectedWaitAt(valNode) } if w.Before != "" { _, err := time.ParseDuration(w.Before) @@ -148,16 +147,16 @@ func (s *Spec) UnmarshalYAML(node *yaml.Node) error { s.Wait = w case "retry": if valNode.Kind != yaml.MappingNode { - return errors.ExpectedMapAt(valNode) + return ExpectedMapAt(valNode) } var r *Retry if err := valNode.Decode(&r); err != nil { - return errors.ExpectedRetryAt(valNode) + return ExpectedRetryAt(valNode) } if r.Attempts != nil { attempts := *r.Attempts if attempts < 1 { - return errors.InvalidRetryAttempts(valNode, attempts) + return InvalidRetryAttempts(valNode, attempts) } } if r.Interval != "" { diff --git a/types/timeout.go b/api/timeout.go similarity index 98% rename from types/timeout.go rename to api/timeout.go index bdd32e9..e38e7c4 100644 --- a/types/timeout.go +++ b/api/timeout.go @@ -2,7 +2,7 @@ // // See the COPYING file in the root project directory for full text. -package types +package api import ( "time" diff --git a/types/wait.go b/api/wait.go similarity index 98% rename from types/wait.go rename to api/wait.go index c5fca16..3b9642b 100644 --- a/types/wait.go +++ b/api/wait.go @@ -2,7 +2,7 @@ // // See the COPYING file in the root project directory for full text. -package types +package api import ( "time" diff --git a/assertion/json/errors.go b/assertion/json/errors.go index 6bdb521..3ccd3af 100644 --- a/assertion/json/errors.go +++ b/assertion/json/errors.go @@ -7,7 +7,7 @@ package json import ( "fmt" - gdterrors "github.com/gdt-dev/gdt/errors" + "github.com/gdt-dev/gdt/api" "gopkg.in/yaml.v3" ) @@ -15,7 +15,7 @@ var ( // ErrJSONPathInvalid returns an ErrParse when a JSONPath expression could // not be parsed. ErrJSONPathInvalid = fmt.Errorf( - "%w: JSONPath invalid", gdterrors.ErrParse, + "%w: JSONPath invalid", api.ErrParse, ) // ErrJSONPathInvalidNoRoot returns an ErrParse when a JSONPath expression // does not start with '$' @@ -24,56 +24,56 @@ var ( ) // ErrJSONUnmarshalError is returned when JSON content cannot be decoded ErrJSONUnmarshalError = fmt.Errorf( - "%w: failed to unmarshal JSON", gdterrors.ErrFailure, + "%w: failed to unmarshal JSON", api.ErrFailure, ) // ErrJSONPathNotFound returns an ErrFailure when a JSONPath expression // could not evaluate to a found element. ErrJSONPathNotFound = fmt.Errorf( - "%w: failed to find element at JSONPath", gdterrors.ErrFailure, + "%w: failed to find element at JSONPath", api.ErrFailure, ) // ErrJSONPathConversionError returns an ErrFailure when a JSONPath // expression evaluated to a found element but could not be converted to a // string. ErrJSONPathConversionError = fmt.Errorf( - "%w: JSONPath value could not be compared", gdterrors.ErrFailure, + "%w: JSONPath value could not be compared", api.ErrFailure, ) // ErrJSONPathNotEqual returns an ErrFailure when a JSONPath // expression evaluated to a found element but the value did not match an // expected string. ErrJSONPathNotEqual = fmt.Errorf( - "%w: JSONPath values not equal", gdterrors.ErrFailure, + "%w: JSONPath values not equal", api.ErrFailure, ) // ErrJSONSchemaValidateError returns an ErrFailure when a JSONSchema could // not be parsed. ErrJSONSchemaValidateError = fmt.Errorf( - "%w: failed to parse JSONSchema", gdterrors.ErrFailure, + "%w: failed to parse JSONSchema", api.ErrFailure, ) // ErrJSONSchemaInvalid returns an ErrFailure when some content could not // be validated with a JSONSchema. ErrJSONSchemaInvalid = fmt.Errorf( - "%w: JSON content did not adhere to JSONSchema", gdterrors.ErrFailure, + "%w: JSON content did not adhere to JSONSchema", api.ErrFailure, ) // ErrJSONFormatError returns an ErrFailure when a JSONFormat expression // could not evaluate to a found element. ErrJSONFormatError = fmt.Errorf( - "%w: failed to determine JSON format", gdterrors.ErrFailure, + "%w: failed to determine JSON format", api.ErrFailure, ) // ErrJSONFormatNotEqual returns an ErrFailure when a an element at a // JSONPath was not in the expected format. ErrJSONFormatNotEqual = fmt.Errorf( - "%w: JSON format not equal", gdterrors.ErrFailure, + "%w: JSON format not equal", api.ErrFailure, ) // ErrJSONSchemaFileNotFound indicates a specified JSONSchema file could // not be found. ErrJSONSchemaFileNotFound = fmt.Errorf( "%w: unable to find JSONSchema file", - gdterrors.ErrParse, + api.ErrParse, ) // ErrUnsupportedJSONSchemaReference indicates that a specified JSONSchema // file is referenced as an HTTP(S) URL instead of a file URI. ErrUnsupportedJSONSchemaReference = fmt.Errorf( "%w: unsupported JSONSchema reference", - gdterrors.ErrParse, + api.ErrParse, ) ) diff --git a/assertion/json/json.go b/assertion/json/json.go index 8a23615..779d1a6 100644 --- a/assertion/json/json.go +++ b/assertion/json/json.go @@ -18,8 +18,7 @@ import ( gjs "github.com/xeipuuv/gojsonschema" "gopkg.in/yaml.v3" - gdterrors "github.com/gdt-dev/gdt/errors" - gdttypes "github.com/gdt-dev/gdt/types" + "github.com/gdt-dev/gdt/api" ) var ( @@ -47,21 +46,21 @@ type Expect struct { // contained in the Expect are valid. func (e *Expect) UnmarshalYAML(node *yaml.Node) error { if node.Kind != yaml.MappingNode { - return gdterrors.ExpectedMapAt(node) + return api.ExpectedMapAt(node) } // maps/structs are stored in a top-level Node.Content field which is a // concatenated slice of Node pointers in pairs of key/values. for i := 0; i < len(node.Content); i += 2 { keyNode := node.Content[i] if keyNode.Kind != yaml.ScalarNode { - return gdterrors.ExpectedScalarAt(keyNode) + return api.ExpectedScalarAt(keyNode) } key := keyNode.Value valNode := node.Content[i+1] switch key { case "len": if valNode.Kind != yaml.ScalarNode { - return gdterrors.ExpectedScalarAt(valNode) + return api.ExpectedScalarAt(valNode) } var v *int if err := valNode.Decode(&v); err != nil { @@ -70,7 +69,7 @@ func (e *Expect) UnmarshalYAML(node *yaml.Node) error { e.Len = v case "schema": if valNode.Kind != yaml.ScalarNode { - return gdterrors.ExpectedScalarAt(valNode) + return api.ExpectedScalarAt(valNode) } // Ensure any JSONSchema URL specified in exponse.json.schema exists schemaURL := valNode.Value @@ -98,7 +97,7 @@ func (e *Expect) UnmarshalYAML(node *yaml.Node) error { } case "paths": if valNode.Kind != yaml.MappingNode { - return gdterrors.ExpectedMapAt(valNode) + return api.ExpectedMapAt(valNode) } paths := map[string]string{} if err := valNode.Decode(&paths); err != nil { @@ -115,7 +114,7 @@ func (e *Expect) UnmarshalYAML(node *yaml.Node) error { e.Paths = paths case "path_formats", "path-formats": if valNode.Kind != yaml.MappingNode { - return gdterrors.ExpectedMapAt(valNode) + return api.ExpectedMapAt(valNode) } pathFormats := map[string]string{} if err := valNode.Decode(&pathFormats); err != nil { @@ -135,12 +134,12 @@ func (e *Expect) UnmarshalYAML(node *yaml.Node) error { return nil } -// New returns a `gdttypes.Assertions` that asserts various conditions about +// New returns a `api.Assertions` that asserts various conditions about // JSON content func New( exp *Expect, content []byte, -) gdttypes.Assertions { +) api.Assertions { return &assertions{ failures: []error{}, exp: exp, @@ -149,7 +148,7 @@ func New( } // assertions represents one or more assertions about JSON data responses and -// implements the gdttypes.Assertions interface +// implements the api.Assertions interface type assertions struct { // failures contains the set of error messages for failed assertions failures []error @@ -200,7 +199,7 @@ func (a *assertions) lenOK() bool { exp := *a.exp.Len got := len(a.content) if exp != got { - a.Fail(gdterrors.NotEqualLength(exp, got)) + a.Fail(api.NotEqualLength(exp, got)) return false } } diff --git a/assertion/json/json_test.go b/assertion/json/json_test.go index 6b2fdbd..5da39ed 100644 --- a/assertion/json/json_test.go +++ b/assertion/json/json_test.go @@ -10,8 +10,8 @@ import ( "path/filepath" "testing" + "github.com/gdt-dev/gdt/api" gdtjson "github.com/gdt-dev/gdt/assertion/json" - gdterrors "github.com/gdt-dev/gdt/errors" "github.com/stretchr/testify/require" "gopkg.in/yaml.v3" ) @@ -61,7 +61,7 @@ paths: notamap `) err = yaml.Unmarshal(content, &exp) require.NotNil(err) - require.ErrorIs(err, gdterrors.ErrExpectedMap) + require.ErrorIs(err, api.ErrExpectedMap) content = []byte(` len: 1 @@ -116,7 +116,7 @@ func TestLength(t *testing.T) { require.False(a.OK(ctx)) failures := a.Failures() require.Len(failures, 1) - require.ErrorIs(failures[0], gdterrors.ErrNotEqual) + require.ErrorIs(failures[0], api.ErrNotEqual) } func TestJSONUnmarshalError(t *testing.T) { diff --git a/context/context.go b/context/context.go index 23469ed..bf9ed38 100644 --- a/context/context.go +++ b/context/context.go @@ -9,8 +9,9 @@ import ( "io" "os" - gdttypes "github.com/gdt-dev/gdt/types" "github.com/samber/lo" + + "github.com/gdt-dev/gdt/api" ) type ContextKey string @@ -88,14 +89,14 @@ func WithDebug(writers ...io.Writer) ContextModifier { } // WithPlugins sets a context's Plugins -func WithPlugins(plugins []gdttypes.Plugin) ContextModifier { +func WithPlugins(plugins []api.Plugin) ContextModifier { return func(ctx context.Context) context.Context { return context.WithValue(ctx, pluginsKey, plugins) } } // WithFixtures sets a context's Fixtures -func WithFixtures(fixtures map[string]gdttypes.Fixture) ContextModifier { +func WithFixtures(fixtures map[string]api.Fixture) ContextModifier { return func(ctx context.Context) context.Context { return context.WithValue(ctx, fixturesKey, fixtures) } @@ -121,7 +122,7 @@ func SetDebug( func RegisterFixture( ctx context.Context, name string, - f gdttypes.Fixture, + f api.Fixture, ) context.Context { fixtures := Fixtures(ctx) fixtures[name] = f @@ -131,7 +132,7 @@ func RegisterFixture( // RegisterPlugin registers a plugin with the context func RegisterPlugin( ctx context.Context, - p gdttypes.Plugin, + p api.Plugin, ) context.Context { plugins := Plugins(ctx) for _, plug := range plugins { diff --git a/context/context_test.go b/context/context_test.go index d026db2..a568b90 100644 --- a/context/context_test.go +++ b/context/context_test.go @@ -8,10 +8,9 @@ import ( "context" "testing" + "github.com/gdt-dev/gdt/api" gdtcontext "github.com/gdt-dev/gdt/context" "github.com/gdt-dev/gdt/fixture" - "github.com/gdt-dev/gdt/result" - gdttypes "github.com/gdt-dev/gdt/types" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" ) @@ -27,23 +26,23 @@ func (d *fooDefaults) UnmarshalYAML(node *yaml.Node) error { } type fooSpec struct { - gdttypes.Spec + api.Spec Foo string `yaml:"foo"` } -func (s *fooSpec) SetBase(b gdttypes.Spec) { +func (s *fooSpec) SetBase(b api.Spec) { s.Spec = b } -func (s *fooSpec) Base() *gdttypes.Spec { +func (s *fooSpec) Base() *api.Spec { return &s.Spec } -func (s *fooSpec) Retry() *gdttypes.Retry { +func (s *fooSpec) Retry() *api.Retry { return nil } -func (s *fooSpec) Timeout() *gdttypes.Timeout { +func (s *fooSpec) Timeout() *api.Timeout { return nil } @@ -51,14 +50,14 @@ func (s *fooSpec) UnmarshalYAML(node *yaml.Node) error { return nil } -func (s *fooSpec) Eval(ctx context.Context) (*result.Result, error) { +func (s *fooSpec) Eval(ctx context.Context) (*api.Result, error) { return nil, nil } type fooPlugin struct{} -func (p *fooPlugin) Info() gdttypes.PluginInfo { - return gdttypes.PluginInfo{ +func (p *fooPlugin) Info() api.PluginInfo { + return api.PluginInfo{ Name: "foo", } } @@ -67,8 +66,8 @@ func (p *fooPlugin) Defaults() yaml.Unmarshaler { return &fooDefaults{} } -func (p *fooPlugin) Specs() []gdttypes.Evaluable { - return []gdttypes.Evaluable{&fooSpec{}} +func (p *fooPlugin) Specs() []api.Evaluable { + return []api.Evaluable{&fooSpec{}} } func TestContext(t *testing.T) { diff --git a/context/getter.go b/context/getter.go index f4f666a..84c1d80 100644 --- a/context/getter.go +++ b/context/getter.go @@ -9,7 +9,7 @@ import ( "io" "strings" - gdttypes "github.com/gdt-dev/gdt/types" + "github.com/gdt-dev/gdt/api" ) const ( @@ -50,25 +50,25 @@ func Debug(ctx context.Context) []io.Writer { } // Plugins gets a context's Plugins -func Plugins(ctx context.Context) []gdttypes.Plugin { +func Plugins(ctx context.Context) []api.Plugin { if ctx == nil { - return []gdttypes.Plugin{} + return []api.Plugin{} } if v := ctx.Value(pluginsKey); v != nil { - return v.([]gdttypes.Plugin) + return v.([]api.Plugin) } - return []gdttypes.Plugin{} + return []api.Plugin{} } // Fixtures gets a context's Fixtures -func Fixtures(ctx context.Context) map[string]gdttypes.Fixture { +func Fixtures(ctx context.Context) map[string]api.Fixture { if ctx == nil { - return map[string]gdttypes.Fixture{} + return map[string]api.Fixture{} } if v := ctx.Value(fixturesKey); v != nil { - return v.(map[string]gdttypes.Fixture) + return v.(map[string]api.Fixture) } - return map[string]gdttypes.Fixture{} + return map[string]api.Fixture{} } // PriorRun gets a context's prior run data diff --git a/context/timeout.go b/context/timeout.go index 62b1beb..b9d599d 100644 --- a/context/timeout.go +++ b/context/timeout.go @@ -9,7 +9,7 @@ import ( "errors" "strings" - gdterrors "github.com/gdt-dev/gdt/errors" + "github.com/gdt-dev/gdt/api" ) // TimedOut evaluates a context and an arbitrary other error and returns true @@ -25,7 +25,7 @@ func TimedOut( return errors.Is(cerr, context.DeadlineExceeded) } if err != nil { - if errors.Is(err, gdterrors.ErrTimeoutExceeded) { + if errors.Is(err, api.ErrTimeoutExceeded) { return true } return strings.Contains(err.Error(), "signal: killed") diff --git a/errors/failure.go b/errors/failure.go deleted file mode 100644 index 10b12f9..0000000 --- a/errors/failure.go +++ /dev/null @@ -1,94 +0,0 @@ -// Use and distribution licensed under the Apache license version 2. -// -// See the COPYING file in the root project directory for full text. - -package errors - -import ( - "errors" - "fmt" -) - -var ( - // ErrFailure is the base error class for all errors that represent failed - // assertions when evaluating a test. - ErrFailure = errors.New("assertion failed") - // ErrTimeoutExceeded is an ErrFailure when a test's execution exceeds a - // timeout length. - ErrTimeoutExceeded = fmt.Errorf("%s: timeout exceeded", ErrFailure) - // ErrNotEqual is an ErrFailure when an expected thing doesn't equal an - // observed thing. - ErrNotEqual = fmt.Errorf("%w: not equal", ErrFailure) - // ErrIn is an ErrFailure when a thing unexpectedly appears in an - // container. - ErrIn = fmt.Errorf("%w: in", ErrFailure) - // ErrNotIn is an ErrFailure when an expected thing doesn't appear in an - // expected container. - ErrNotIn = fmt.Errorf("%w: not in", ErrFailure) - // ErrNoneIn is an ErrFailure when none of a list of elements appears in an - // expected container. - ErrNoneIn = fmt.Errorf("%w: none in", ErrFailure) - // ErrUnexpectedError is an ErrFailure when an unexpected error has - // occurred. - ErrUnexpectedError = fmt.Errorf("%w: unexpected error", ErrFailure) -) - -// TimeoutExceeded returns an ErrTimeoutExceeded when a test's execution -// exceeds a timeout length. The optional failure parameter indicates a failed -// assertion that occurred before a timeout was reached. -func TimeoutExceeded(duration string, failure error) error { - if failure != nil { - return fmt.Errorf( - "%w: timed out waiting for assertion to succeed (%s)", - failure, duration, - ) - } - return fmt.Errorf("%s (%s)", ErrTimeoutExceeded, duration) -} - -// NotEqualLength returns an ErrNotEqual when an expected length doesn't -// equal an observed length. -func NotEqualLength(exp, got int) error { - return fmt.Errorf( - "%w: expected length of %d but got %d", - ErrNotEqual, exp, got, - ) -} - -// NotEqual returns an ErrNotEqual when an expected thing doesn't equal an -// observed thing. -func NotEqual(exp, got interface{}) error { - return fmt.Errorf("%w: expected %v but got %v", ErrNotEqual, exp, got) -} - -// In returns an ErrIn when a thing unexpectedly appears in a container. -func In(element, container interface{}) error { - return fmt.Errorf( - "%w: expected %v not to contain %v", - ErrIn, container, element, - ) -} - -// NotIn returns an ErrNotIn when an expected thing doesn't appear in an -// expected container. -func NotIn(element, container interface{}) error { - return fmt.Errorf( - "%w: expected %v to contain %v", - ErrNotIn, container, element, - ) -} - -// NoneIn returns an ErrNoneIn when none of a list of elements appears in an -// expected container. -func NoneIn(elements, container interface{}) error { - return fmt.Errorf( - "%w: expected %v to contain one of %v", - ErrNoneIn, container, elements, - ) -} - -// UnexpectedError returns an ErrUnexpectedError when a supplied error is not -// expected. -func UnexpectedError(err error) error { - return fmt.Errorf("%w: %s", ErrUnexpectedError, err) -} diff --git a/errors/runtime.go b/errors/runtime.go deleted file mode 100644 index 734e9c5..0000000 --- a/errors/runtime.go +++ /dev/null @@ -1,28 +0,0 @@ -// Use and distribution licensed under the Apache license version 2. -// -// See the COPYING file in the root project directory for full text. - -package errors - -import ( - "errors" - "fmt" -) - -var ( - // RuntimeError is the base error class for all errors occurring during - // runtime (and not during the parsing of a scenario or spec) - RuntimeError = errors.New("runtime error") - // ErrRequiredFixture is returned when a required fixture has not - // been registered with the context. - ErrRequiredFixture = fmt.Errorf( - "%w: required fixture missing", - RuntimeError, - ) -) - -// RequiredFixtureMissing returns an ErrRequiredFixture with the supplied -// fixture name -func RequiredFixtureMissing(name string) error { - return fmt.Errorf("%w: %s", ErrRequiredFixture, name) -} diff --git a/fixture/generic.go b/fixture/generic.go index f1102ff..ee3ba5d 100644 --- a/fixture/generic.go +++ b/fixture/generic.go @@ -8,7 +8,7 @@ import ( "context" "strings" - gdttypes "github.com/gdt-dev/gdt/types" + "github.com/gdt-dev/gdt/api" ) // genericFixture adapts functions and state dicts into the Fixture type @@ -77,7 +77,7 @@ func WithState(state map[string]interface{}) genericFixtureModifier { } // New returns a new generic Fixture -func New(mods ...genericFixtureModifier) gdttypes.Fixture { +func New(mods ...genericFixtureModifier) api.Fixture { f := &genericFixture{} for _, mod := range mods { mod(f) diff --git a/fixture/json/json.go b/fixture/json/json.go index 69f6b3a..c1a421d 100644 --- a/fixture/json/json.go +++ b/fixture/json/json.go @@ -11,7 +11,8 @@ import ( "strconv" "github.com/PaesslerAG/jsonpath" - gdttypes "github.com/gdt-dev/gdt/types" + + "github.com/gdt-dev/gdt/api" ) type jsonFixture struct { @@ -59,8 +60,8 @@ func (f *jsonFixture) State(path string) interface{} { } // New takes a string, some bytes or an io.Reader and returns a new -// gdttypes.Fixture that can have its state queried via JSONPath -func New(data interface{}) (gdttypes.Fixture, error) { +// api.Fixture that can have its state queried via JSONPath +func New(data interface{}) (api.Fixture, error) { var err error var b []byte switch data := data.(type) { diff --git a/fixture/json/json_test.go b/fixture/json/json_test.go index 9402757..9f04770 100644 --- a/fixture/json/json_test.go +++ b/fixture/json/json_test.go @@ -8,8 +8,8 @@ import ( "bytes" "testing" + "github.com/gdt-dev/gdt/api" jsonfix "github.com/gdt-dev/gdt/fixture/json" - gdttypes "github.com/gdt-dev/gdt/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -23,7 +23,7 @@ func TestNewFromString(t *testing.T) { require.Nil(err) require.NotNil(f) - require.Implements((*gdttypes.Fixture)(nil), f) + require.Implements((*api.Fixture)(nil), f) assert.True(f.HasState("$.book.year")) assert.Equal("1957", f.State("$.book.year")) @@ -40,7 +40,7 @@ func TestNewFromBytes(t *testing.T) { require.Nil(err) require.NotNil(f) - require.Implements((*gdttypes.Fixture)(nil), f) + require.Implements((*api.Fixture)(nil), f) assert.True(f.HasState("$.book.year")) assert.Equal("1957", f.State("$.book.year")) @@ -58,7 +58,7 @@ func TestNewFromReader(t *testing.T) { require.Nil(err) require.NotNil(f) - require.Implements((*gdttypes.Fixture)(nil), f) + require.Implements((*api.Fixture)(nil), f) assert.True(f.HasState("$.book.year")) assert.Equal("1957", f.State("$.book.year")) diff --git a/plugin/exec/action.go b/plugin/exec/action.go index d172ef0..687f5ef 100644 --- a/plugin/exec/action.go +++ b/plugin/exec/action.go @@ -9,9 +9,9 @@ import ( "context" "os/exec" + "github.com/gdt-dev/gdt/api" gdtcontext "github.com/gdt-dev/gdt/context" "github.com/gdt-dev/gdt/debug" - gdterrors "github.com/gdt-dev/gdt/errors" "github.com/google/shlex" ) @@ -69,7 +69,7 @@ func (a *Action) Do( err = cmd.Start() if gdtcontext.TimedOut(ctx, err) { - return gdterrors.ErrTimeoutExceeded + return api.ErrTimeoutExceeded } if err != nil { return err @@ -93,7 +93,7 @@ func (a *Action) Do( err = cmd.Wait() if gdtcontext.TimedOut(ctx, err) { - return gdterrors.ErrTimeoutExceeded + return api.ErrTimeoutExceeded } if err != nil && exitcode != nil { eerr, _ := err.(*exec.ExitError) diff --git a/plugin/exec/assertions.go b/plugin/exec/assertions.go index 6e361c2..defebb0 100644 --- a/plugin/exec/assertions.go +++ b/plugin/exec/assertions.go @@ -9,8 +9,7 @@ import ( "context" "strings" - "github.com/gdt-dev/gdt/errors" - gdttypes "github.com/gdt-dev/gdt/types" + "github.com/gdt-dev/gdt/api" ) // Expect contains the assertions about an Exec Spec's actions @@ -29,13 +28,13 @@ type Expect struct { type PipeExpect struct { // ContainsAll is one or more strings that *all* must be present in the // contents of the pipe - ContainsAll *gdttypes.FlexStrings `yaml:"contains,omitempty"` + ContainsAll *api.FlexStrings `yaml:"contains,omitempty"` // ContainsNone is one or more strings, *none of which* should be present in // the contents of the pipe - ContainsNone *gdttypes.FlexStrings `yaml:"contains-none-of,omitempty"` + ContainsNone *api.FlexStrings `yaml:"contains-none-of,omitempty"` // ContainsOneOf is one or more strings of which *at least one* must be // present in the contents of the pipe - ContainsAny *gdttypes.FlexStrings `yaml:"contains-one-of,omitempty"` + ContainsAny *api.FlexStrings `yaml:"contains-one-of,omitempty"` } // pipeAssertions contains assertions about the contents of a pipe @@ -54,7 +53,7 @@ func (a *pipeAssertions) Fail(err error) { a.failures = append(a.failures, err) } -// Failures returns a slice of errors for all failed assertions +// Failures returns a slice of api for all failed assertions func (a *pipeAssertions) Failures() []error { if a == nil { return []error{} @@ -77,13 +76,13 @@ func (a *pipeAssertions) OK(ctx context.Context) bool { vals := a.ContainsAll.Values() if len(vals) == 1 { if !strings.Contains(contents, vals[0]) { - a.Fail(errors.NotEqual(vals[0], contents)) + a.Fail(api.NotEqual(vals[0], contents)) res = false } } else { for _, find := range vals { if !strings.Contains(contents, find) { - a.Fail(errors.NotIn(find, a.name)) + a.Fail(api.NotIn(find, a.name)) res = false } } @@ -98,14 +97,14 @@ func (a *pipeAssertions) OK(ctx context.Context) bool { } } if !found { - a.Fail(errors.NoneIn(a.ContainsAny.Values(), a.name)) + a.Fail(api.NoneIn(a.ContainsAny.Values(), a.name)) res = false } } if a.ContainsNone != nil { for _, find := range a.ContainsNone.Values() { if strings.Contains(contents, find) { - a.Fail(errors.In(find, a.name)) + a.Fail(api.In(find, a.name)) res = false } } @@ -132,7 +131,7 @@ func (a *assertions) Fail(err error) { a.failures = append(a.failures, err) } -// Failures returns a slice of errors for all failed assertions +// Failures returns a slice of api for all failed assertions func (a *assertions) Failures() []error { if a == nil { return []error{} @@ -145,7 +144,7 @@ func (a *assertions) Failures() []error { func (a *assertions) OK(ctx context.Context) bool { res := true if a.expExitCode != a.exitCode { - a.Fail(errors.NotEqual(a.expExitCode, a.exitCode)) + a.Fail(api.NotEqual(a.expExitCode, a.exitCode)) res = false } if !a.expOutPipe.OK(ctx) { @@ -166,7 +165,7 @@ func newAssertions( exitCode int, outPipe *bytes.Buffer, errPipe *bytes.Buffer, -) gdttypes.Assertions { +) api.Assertions { a := &assertions{ failures: []error{}, expExitCode: exitCode, diff --git a/plugin/exec/defaults.go b/plugin/exec/defaults.go index 5be9bd9..657e3e1 100644 --- a/plugin/exec/defaults.go +++ b/plugin/exec/defaults.go @@ -7,7 +7,7 @@ package exec import ( "gopkg.in/yaml.v3" - "github.com/gdt-dev/gdt/errors" + "github.com/gdt-dev/gdt/api" ) type execDefaults struct{} @@ -19,21 +19,21 @@ type Defaults struct { func (d *Defaults) UnmarshalYAML(node *yaml.Node) error { if node.Kind != yaml.MappingNode { - return errors.ExpectedMapAt(node) + return api.ExpectedMapAt(node) } // maps/structs are stored in a top-level Node.Content field which is a // concatenated slice of Node pointers in pairs of key/values. for i := 0; i < len(node.Content); i += 2 { keyNode := node.Content[i] if keyNode.Kind != yaml.ScalarNode { - return errors.ExpectedScalarAt(keyNode) + return api.ExpectedScalarAt(keyNode) } key := keyNode.Value valNode := node.Content[i+1] switch key { case "exec": if valNode.Kind != yaml.MappingNode { - return errors.ExpectedMapAt(valNode) + return api.ExpectedMapAt(valNode) } ed := execDefaults{} if err := valNode.Decode(&ed); err != nil { diff --git a/plugin/exec/errors.go b/plugin/exec/errors.go index fa7833b..1cb7ba1 100644 --- a/plugin/exec/errors.go +++ b/plugin/exec/errors.go @@ -9,18 +9,18 @@ import ( "gopkg.in/yaml.v3" - gdterrors "github.com/gdt-dev/gdt/errors" + "github.com/gdt-dev/gdt/api" ) var ( // ErrExecEmpty indicates that the user specified an empty "exec" // field ErrExecEmpty = fmt.Errorf( - "%w: expected non-empty exec field", gdterrors.ErrParse, + "%w: expected non-empty exec field", api.ErrParse, ) // ErrExecInvalid indicates that the user specified an invalid "exec" field ErrExecInvalid = fmt.Errorf( - "%w: invalid exec field", gdterrors.ErrParse, + "%w: invalid exec field", api.ErrParse, ) ) @@ -44,5 +44,5 @@ func ExecInvalidShellParse(err error, node *yaml.Node) error { // ExecRuntimeError returns a RuntimeError with an error from the Exec() call. func ExecRuntimeError(err error) error { - return fmt.Errorf("%w: %s", gdterrors.RuntimeError, err) + return fmt.Errorf("%w: %s", api.RuntimeError, err) } diff --git a/plugin/exec/eval.go b/plugin/exec/eval.go index a02d3cf..45ec494 100644 --- a/plugin/exec/eval.go +++ b/plugin/exec/eval.go @@ -8,9 +8,8 @@ import ( "bytes" "context" + "github.com/gdt-dev/gdt/api" "github.com/gdt-dev/gdt/debug" - gdterrors "github.com/gdt-dev/gdt/errors" - "github.com/gdt-dev/gdt/result" ) // Eval performs an action and evaluates the results of that action, returning @@ -20,15 +19,15 @@ import ( // Errors returned by Eval() are **RuntimeErrors**, not failures in assertions. func (s *Spec) Eval( ctx context.Context, -) (*result.Result, error) { +) (*api.Result, error) { outbuf := &bytes.Buffer{} errbuf := &bytes.Buffer{} var ec int if err := s.Do(ctx, outbuf, errbuf, &ec); err != nil { - if err == gdterrors.ErrTimeoutExceeded { - return result.New(result.WithFailures(gdterrors.ErrTimeoutExceeded)), nil + if err == api.ErrTimeoutExceeded { + return api.NewResult(api.WithFailures(api.ErrTimeoutExceeded)), nil } return nil, ExecRuntimeError(err) } @@ -45,5 +44,5 @@ func (s *Spec) Eval( } } } - return result.New(result.WithFailures(a.Failures()...)), nil + return api.NewResult(api.WithFailures(a.Failures()...)), nil } diff --git a/plugin/exec/parse.go b/plugin/exec/parse.go index 939104e..295d5a0 100644 --- a/plugin/exec/parse.go +++ b/plugin/exec/parse.go @@ -14,14 +14,13 @@ import ( "github.com/samber/lo" "gopkg.in/yaml.v3" - "github.com/gdt-dev/gdt/errors" - gdttypes "github.com/gdt-dev/gdt/types" + "github.com/gdt-dev/gdt/api" ) var ( // ErrUnknownShell returns an ErrParse when an unknown shell is specified ErrUnknownShell = fmt.Errorf( - "%w: unknown shell", errors.ErrParse, + "%w: unknown shell", api.ErrParse, ) ) @@ -35,7 +34,7 @@ func UnknownShell(shell string) error { func (s *Spec) UnmarshalYAML(node *yaml.Node) error { if node.Kind != yaml.MappingNode { - return errors.ExpectedMapAt(node) + return api.ExpectedMapAt(node) } var execValNode *yaml.Node // maps/structs are stored in a top-level Node.Content field which is a @@ -43,14 +42,14 @@ func (s *Spec) UnmarshalYAML(node *yaml.Node) error { for i := 0; i < len(node.Content); i += 2 { keyNode := node.Content[i] if keyNode.Kind != yaml.ScalarNode { - return errors.ExpectedScalarAt(keyNode) + return api.ExpectedScalarAt(keyNode) } key := keyNode.Value valNode := node.Content[i+1] switch key { case "shell": if valNode.Kind != yaml.ScalarNode { - return errors.ExpectedScalarAt(valNode) + return api.ExpectedScalarAt(valNode) } s.Shell = strings.TrimSpace(valNode.Value) if _, err := exec.LookPath(s.Shell); err != nil { @@ -58,7 +57,7 @@ func (s *Spec) UnmarshalYAML(node *yaml.Node) error { } case "exec": if valNode.Kind != yaml.ScalarNode { - return errors.ExpectedScalarAt(valNode) + return api.ExpectedScalarAt(valNode) } execValNode = valNode s.Exec = strings.TrimSpace(valNode.Value) @@ -67,7 +66,7 @@ func (s *Spec) UnmarshalYAML(node *yaml.Node) error { } case "assert": if valNode.Kind != yaml.MappingNode { - return errors.ExpectedMapAt(valNode) + return api.ExpectedMapAt(valNode) } var e *Expect if err := valNode.Decode(&e); err != nil { @@ -76,7 +75,7 @@ func (s *Spec) UnmarshalYAML(node *yaml.Node) error { s.Assert = e case "on": if valNode.Kind != yaml.MappingNode { - return errors.ExpectedMapAt(valNode) + return api.ExpectedMapAt(valNode) } var o *On if err := valNode.Decode(&o); err != nil { @@ -84,10 +83,10 @@ func (s *Spec) UnmarshalYAML(node *yaml.Node) error { } s.On = o default: - if lo.Contains(gdttypes.BaseSpecFields, key) { + if lo.Contains(api.BaseSpecFields, key) { continue } - return errors.UnknownFieldAt(key, keyNode) + return api.UnknownFieldAt(key, keyNode) } } if s.Exec == "" { @@ -104,21 +103,21 @@ func (s *Spec) UnmarshalYAML(node *yaml.Node) error { func (e *Expect) UnmarshalYAML(node *yaml.Node) error { if node.Kind != yaml.MappingNode { - return errors.ExpectedMapAt(node) + return api.ExpectedMapAt(node) } // maps/structs are stored in a top-level Node.Content field which is a // concatenated slice of Node pointers in pairs of key/values. for i := 0; i < len(node.Content); i += 2 { keyNode := node.Content[i] if keyNode.Kind != yaml.ScalarNode { - return errors.ExpectedScalarAt(keyNode) + return api.ExpectedScalarAt(keyNode) } key := keyNode.Value valNode := node.Content[i+1] switch key { case "exit_code", "exit-code": if valNode.Kind != yaml.ScalarNode { - return errors.ExpectedScalarAt(valNode) + return api.ExpectedScalarAt(valNode) } ec, err := strconv.Atoi(valNode.Value) if err != nil { @@ -127,7 +126,7 @@ func (e *Expect) UnmarshalYAML(node *yaml.Node) error { e.ExitCode = ec case "out": if valNode.Kind != yaml.MappingNode { - return errors.ExpectedMapAt(valNode) + return api.ExpectedMapAt(valNode) } var pe *PipeExpect if err := valNode.Decode(&pe); err != nil { @@ -136,7 +135,7 @@ func (e *Expect) UnmarshalYAML(node *yaml.Node) error { e.Out = pe case "err": if valNode.Kind != yaml.MappingNode { - return errors.ExpectedMapAt(valNode) + return api.ExpectedMapAt(valNode) } var pe *PipeExpect if err := valNode.Decode(&pe); err != nil { @@ -144,7 +143,7 @@ func (e *Expect) UnmarshalYAML(node *yaml.Node) error { } e.Err = pe default: - return errors.UnknownFieldAt(key, keyNode) + return api.UnknownFieldAt(key, keyNode) } } return nil @@ -152,47 +151,47 @@ func (e *Expect) UnmarshalYAML(node *yaml.Node) error { func (e *PipeExpect) UnmarshalYAML(node *yaml.Node) error { if node.Kind != yaml.MappingNode { - return errors.ExpectedMapAt(node) + return api.ExpectedMapAt(node) } // maps/structs are stored in a top-level Node.Content field which is a // concatenated slice of Node pointers in pairs of key/values. for i := 0; i < len(node.Content); i += 2 { keyNode := node.Content[i] if keyNode.Kind != yaml.ScalarNode { - return errors.ExpectedScalarAt(keyNode) + return api.ExpectedScalarAt(keyNode) } key := keyNode.Value valNode := node.Content[i+1] switch key { case "all", "is", "contains", "contains-all", "contains_all": if valNode.Kind != yaml.ScalarNode && valNode.Kind != yaml.SequenceNode { - return errors.ExpectedScalarOrSequenceAt(valNode) + return api.ExpectedScalarOrSequenceAt(valNode) } - var v gdttypes.FlexStrings + var v api.FlexStrings if err := valNode.Decode(&v); err != nil { return err } e.ContainsAll = &v case "any", "contains-one-of", "contains-any", "contains_one_of", "contains_any": if valNode.Kind != yaml.ScalarNode && valNode.Kind != yaml.SequenceNode { - return errors.ExpectedScalarOrSequenceAt(valNode) + return api.ExpectedScalarOrSequenceAt(valNode) } - var v gdttypes.FlexStrings + var v api.FlexStrings if err := valNode.Decode(&v); err != nil { return err } e.ContainsAny = &v case "none", "none-of", "contains-none-of", "contains-none", "none_of", "contains_none_of", "contains_none": if valNode.Kind != yaml.ScalarNode && valNode.Kind != yaml.SequenceNode { - return errors.ExpectedScalarOrSequenceAt(valNode) + return api.ExpectedScalarOrSequenceAt(valNode) } - var v gdttypes.FlexStrings + var v api.FlexStrings if err := valNode.Decode(&v); err != nil { return err } e.ContainsNone = &v default: - return errors.UnknownFieldAt(key, keyNode) + return api.UnknownFieldAt(key, keyNode) } } return nil diff --git a/plugin/exec/parse_test.go b/plugin/exec/parse_test.go index bc0e697..c79b419 100644 --- a/plugin/exec/parse_test.go +++ b/plugin/exec/parse_test.go @@ -9,10 +9,9 @@ import ( "path/filepath" "testing" - "github.com/gdt-dev/gdt/errors" + "github.com/gdt-dev/gdt/api" gdtexec "github.com/gdt-dev/gdt/plugin/exec" "github.com/gdt-dev/gdt/scenario" - gdttypes "github.com/gdt-dev/gdt/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -31,7 +30,7 @@ func TestUnknownShell(t *testing.T) { ) assert.NotNil(err) assert.ErrorIs(err, gdtexec.ErrUnknownShell) - assert.ErrorIs(err, errors.ErrParse) + assert.ErrorIs(err, api.ErrParse) assert.Nil(s) } @@ -51,11 +50,11 @@ func TestSimpleCommand(t *testing.T) { assert.NotNil(s) assert.IsType(&scenario.Scenario{}, s) - expTests := []gdttypes.Evaluable{ + expTests := []api.Evaluable{ &gdtexec.Spec{ - Spec: gdttypes.Spec{ + Spec: api.Spec{ Index: 0, - Defaults: &gdttypes.Defaults{}, + Defaults: &api.Defaults{}, }, Action: gdtexec.Action{ Exec: "ls", diff --git a/plugin/exec/plugin.go b/plugin/exec/plugin.go index 222c86d..87fac20 100644 --- a/plugin/exec/plugin.go +++ b/plugin/exec/plugin.go @@ -7,8 +7,8 @@ package exec import ( "gopkg.in/yaml.v3" + "github.com/gdt-dev/gdt/api" gdtplugin "github.com/gdt-dev/gdt/plugin" - gdttypes "github.com/gdt-dev/gdt/types" ) var ( @@ -30,10 +30,10 @@ const ( type plugin struct{} -func (p *plugin) Info() gdttypes.PluginInfo { - return gdttypes.PluginInfo{ +func (p *plugin) Info() api.PluginInfo { + return api.PluginInfo{ Name: pluginName, - Timeout: &gdttypes.Timeout{ + Timeout: &api.Timeout{ After: DefaultTimeout, }, } @@ -43,11 +43,11 @@ func (p *plugin) Defaults() yaml.Unmarshaler { return &Defaults{} } -func (p *plugin) Specs() []gdttypes.Evaluable { - return []gdttypes.Evaluable{&Spec{}} +func (p *plugin) Specs() []api.Evaluable { + return []api.Evaluable{&Spec{}} } // Plugin returns the HTTP gdt plugin -func Plugin() gdttypes.Plugin { +func Plugin() api.Plugin { return &plugin{} } diff --git a/plugin/exec/spec.go b/plugin/exec/spec.go index fa591da..5cb76c1 100644 --- a/plugin/exec/spec.go +++ b/plugin/exec/spec.go @@ -5,13 +5,13 @@ package exec import ( - gdttypes "github.com/gdt-dev/gdt/types" + "github.com/gdt-dev/gdt/api" ) // Spec describes a single Spec that executes one or more commands via the // operating system's `exec` family of functions. type Spec struct { - gdttypes.Spec + api.Spec Action // Assert is an object containing the conditions that the Spec will assert. Assert *Expect `yaml:"assert,omitempty"` @@ -19,18 +19,18 @@ type Spec struct { On *On `yaml:"on,omitempty"` } -func (s *Spec) SetBase(b gdttypes.Spec) { +func (s *Spec) SetBase(b api.Spec) { s.Spec = b } -func (s *Spec) Base() *gdttypes.Spec { +func (s *Spec) Base() *api.Spec { return &s.Spec } -func (s *Spec) Retry() *gdttypes.Retry { +func (s *Spec) Retry() *api.Retry { return nil } -func (s *Spec) Timeout() *gdttypes.Timeout { +func (s *Spec) Timeout() *api.Timeout { return nil } diff --git a/plugin/registry.go b/plugin/registry.go index 1354ea1..023ddd4 100644 --- a/plugin/registry.go +++ b/plugin/registry.go @@ -8,18 +8,18 @@ import ( "strings" "sync" - gdttypes "github.com/gdt-dev/gdt/types" + "github.com/gdt-dev/gdt/api" ) // registry stores a set of Plugins and is safe to use in threaded // environments. type registry struct { sync.RWMutex - entries map[string]gdttypes.Plugin + entries map[string]api.Plugin } // Remove delists the Plugin with registry. Only really useful for testing. -func (r *registry) Remove(p gdttypes.Plugin) { +func (r *registry) Remove(p api.Plugin) { r.Lock() defer r.Unlock() lowered := strings.ToLower(p.Info().Name) @@ -27,7 +27,7 @@ func (r *registry) Remove(p gdttypes.Plugin) { } // Add registers a Plugin with the registry. -func (r *registry) Add(p gdttypes.Plugin) { +func (r *registry) Add(p api.Plugin) { r.Lock() defer r.Unlock() lowered := strings.ToLower(p.Info().Name) @@ -35,10 +35,10 @@ func (r *registry) Add(p gdttypes.Plugin) { } // List returns a slice of Plugins that are registered with gdt. -func (r *registry) List() []gdttypes.Plugin { +func (r *registry) List() []api.Plugin { r.RLock() defer r.RUnlock() - res := []gdttypes.Plugin{} + res := []api.Plugin{} for _, p := range r.entries { res = append(res, p) } @@ -47,7 +47,7 @@ func (r *registry) List() []gdttypes.Plugin { var ( knownPlugins = ®istry{ - entries: map[string]gdttypes.Plugin{}, + entries: map[string]api.Plugin{}, } ) @@ -55,11 +55,11 @@ var ( // // Generally only plugin authors will ever need to call this function. It is // not required for normal use of gdt or any known plugin. -func Register(p gdttypes.Plugin) { +func Register(p api.Plugin) { knownPlugins.Add(p) } // Registered returns a slice of pointers to gdt's known plugins. -func Registered() []gdttypes.Plugin { +func Registered() []api.Plugin { return knownPlugins.List() } diff --git a/plugin/registry_test.go b/plugin/registry_test.go index 59fe284..769443b 100644 --- a/plugin/registry_test.go +++ b/plugin/registry_test.go @@ -8,9 +8,8 @@ import ( "context" "testing" + "github.com/gdt-dev/gdt/api" "github.com/gdt-dev/gdt/plugin" - "github.com/gdt-dev/gdt/result" - gdttypes "github.com/gdt-dev/gdt/types" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" ) @@ -24,27 +23,27 @@ func (d *fooDefaults) UnmarshalYAML(node *yaml.Node) error { } type fooSpec struct { - gdttypes.Spec + api.Spec Foo string `yaml:"foo"` } -func (s *fooSpec) SetBase(b gdttypes.Spec) { +func (s *fooSpec) SetBase(b api.Spec) { s.Spec = b } -func (s *fooSpec) Base() *gdttypes.Spec { +func (s *fooSpec) Base() *api.Spec { return &s.Spec } -func (s *fooSpec) Retry() *gdttypes.Retry { +func (s *fooSpec) Retry() *api.Retry { return nil } -func (s *fooSpec) Timeout() *gdttypes.Timeout { +func (s *fooSpec) Timeout() *api.Timeout { return nil } -func (s *fooSpec) Eval(context.Context) (*result.Result, error) { +func (s *fooSpec) Eval(context.Context) (*api.Result, error) { return nil, nil } @@ -54,8 +53,8 @@ func (s *fooSpec) UnmarshalYAML(node *yaml.Node) error { type fooPlugin struct{} -func (p *fooPlugin) Info() gdttypes.PluginInfo { - return gdttypes.PluginInfo{ +func (p *fooPlugin) Info() api.PluginInfo { + return api.PluginInfo{ Name: "foo", } } @@ -64,8 +63,8 @@ func (p *fooPlugin) Defaults() yaml.Unmarshaler { return &fooDefaults{} } -func (p *fooPlugin) Specs() []gdttypes.Evaluable { - return []gdttypes.Evaluable{&fooSpec{}} +func (p *fooPlugin) Specs() []api.Evaluable { + return []api.Evaluable{&fooSpec{}} } func TestRegisterAndList(t *testing.T) { diff --git a/porcelain.go b/porcelain.go index 743779b..0d7d7b4 100644 --- a/porcelain.go +++ b/porcelain.go @@ -8,8 +8,8 @@ import ( "io" "os" + "github.com/gdt-dev/gdt/api" gdtcontext "github.com/gdt-dev/gdt/context" - gdterrors "github.com/gdt-dev/gdt/errors" jsonfix "github.com/gdt-dev/gdt/fixture/json" "github.com/gdt-dev/gdt/plugin" _ "github.com/gdt-dev/gdt/plugin/exec" @@ -85,7 +85,7 @@ var ( // with `go test -v=test2json`. SetDebug = gdtcontext.SetDebug // NewJSONFixture takes a string, some bytes or an io.Reader and returns a - // new gdttypes.Fixture that can have its state queried via JSONPath + // new api.Fixture that can have its state queried via JSONPath NewJSONFixture = jsonfix.New ) @@ -124,6 +124,6 @@ func From(source interface{}) (*suite.Suite, error) { } return suite.FromScenario(s), nil default: - return nil, gdterrors.UnknownSourceType(source) + return nil, api.UnknownSourceType(source) } } diff --git a/porcelain_test.go b/porcelain_test.go index 4f89b94..3edac1a 100644 --- a/porcelain_test.go +++ b/porcelain_test.go @@ -11,7 +11,7 @@ import ( "testing" "github.com/gdt-dev/gdt" - gdterrors "github.com/gdt-dev/gdt/errors" + "github.com/gdt-dev/gdt/api" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -24,7 +24,7 @@ func TestFromUnknownSourceType(t *testing.T) { require.NotNil(err) require.Nil(s) - assert.ErrorIs(err, gdterrors.ErrUnknownSourceType) + assert.ErrorIs(err, api.ErrUnknownSourceType) } func TestFromFileNotFound(t *testing.T) { diff --git a/scenario/defaults.go b/scenario/defaults.go index 68fff91..95bb250 100644 --- a/scenario/defaults.go +++ b/scenario/defaults.go @@ -7,9 +7,9 @@ package scenario import ( "time" - "github.com/gdt-dev/gdt/errors" - gdttypes "github.com/gdt-dev/gdt/types" "gopkg.in/yaml.v3" + + "github.com/gdt-dev/gdt/api" ) const ( @@ -24,33 +24,33 @@ const ( type Defaults struct { // Timeout has fields that represent the default timeout behaviour and // expectations to use for test specs in the scenario. - Timeout *gdttypes.Timeout `yaml:"timeout,omitempty"` + Timeout *api.Timeout `yaml:"timeout,omitempty"` // Retry has fields that represent the default retry behaviour for test // specs in the scenario. - Retry *gdttypes.Retry `yaml:"retry,omitempty"` + Retry *api.Retry `yaml:"retry,omitempty"` } func (d *Defaults) UnmarshalYAML(node *yaml.Node) error { if node.Kind != yaml.MappingNode { - return errors.ExpectedMapAt(node) + return api.ExpectedMapAt(node) } // maps/structs are stored in a top-level Node.Content field which is a // concatenated slice of Node pointers in pairs of key/values. for i := 0; i < len(node.Content); i += 2 { keyNode := node.Content[i] if keyNode.Kind != yaml.ScalarNode { - return errors.ExpectedScalarAt(keyNode) + return api.ExpectedScalarAt(keyNode) } key := keyNode.Value valNode := node.Content[i+1] switch key { case "timeout": if valNode.Kind != yaml.MappingNode { - return errors.ExpectedMapAt(valNode) + return api.ExpectedMapAt(valNode) } - var to *gdttypes.Timeout + var to *api.Timeout if err := valNode.Decode(&to); err != nil { - return errors.ExpectedTimeoutAt(valNode) + return api.ExpectedTimeoutAt(valNode) } _, err := time.ParseDuration(to.After) if err != nil { @@ -59,16 +59,16 @@ func (d *Defaults) UnmarshalYAML(node *yaml.Node) error { d.Timeout = to case "retry": if valNode.Kind != yaml.MappingNode { - return errors.ExpectedMapAt(valNode) + return api.ExpectedMapAt(valNode) } - var r *gdttypes.Retry + var r *api.Retry if err := valNode.Decode(&r); err != nil { - return errors.ExpectedRetryAt(valNode) + return api.ExpectedRetryAt(valNode) } if r.Attempts != nil { attempts := *r.Attempts if attempts < 1 { - return errors.InvalidRetryAttempts(valNode, attempts) + return api.InvalidRetryAttempts(valNode, attempts) } } if r.Interval != "" { diff --git a/scenario/parse.go b/scenario/parse.go index 753432e..4f34698 100644 --- a/scenario/parse.go +++ b/scenario/parse.go @@ -9,19 +9,18 @@ import ( "gopkg.in/yaml.v3" - gdterrors "github.com/gdt-dev/gdt/errors" + "github.com/gdt-dev/gdt/api" "github.com/gdt-dev/gdt/plugin" - gdttypes "github.com/gdt-dev/gdt/types" ) // UnmarshalYAML is a custom unmarshaler that asks plugins for their known spec // types and attempts to unmarshal test spec contents into those types. func (s *Scenario) UnmarshalYAML(node *yaml.Node) error { if node.Kind != yaml.MappingNode { - return gdterrors.ExpectedMapAt(node) + return api.ExpectedMapAt(node) } plugins := plugin.Registered() - defaults := gdttypes.Defaults{} + defaults := api.Defaults{} // maps/structs are stored in a top-level Node.Content field which is a // concatenated slice of Node pointers in pairs of key/values. // @@ -32,38 +31,38 @@ func (s *Scenario) UnmarshalYAML(node *yaml.Node) error { for i := 0; i < len(node.Content); i += 2 { keyNode := node.Content[i] if keyNode.Kind != yaml.ScalarNode { - return gdterrors.ExpectedScalarAt(keyNode) + return api.ExpectedScalarAt(keyNode) } key := keyNode.Value valNode := node.Content[i+1] switch key { case "name": if valNode.Kind != yaml.ScalarNode { - return gdterrors.ExpectedScalarAt(valNode) + return api.ExpectedScalarAt(valNode) } s.Name = valNode.Value case "description": if valNode.Kind != yaml.ScalarNode { - return gdterrors.ExpectedScalarAt(valNode) + return api.ExpectedScalarAt(valNode) } s.Description = valNode.Value case "fixtures": if valNode.Kind != yaml.SequenceNode { - return gdterrors.ExpectedSequenceAt(valNode) + return api.ExpectedSequenceAt(valNode) } var fixtures []string if err := valNode.Decode(&fixtures); err != nil { - return gdterrors.ExpectedSequenceAt(valNode) + return api.ExpectedSequenceAt(valNode) } s.Fixtures = fixtures case "defaults": if valNode.Kind != yaml.MappingNode { - return gdterrors.ExpectedMapAt(valNode) + return api.ExpectedMapAt(valNode) } // Each plugin can have its own set of default configuration values // under an outer map field keyed to the name of the plugin. // Plugins return a Defaults prototype from - // `gdttypes.Plugin.Defaults()` that understands how to parse a + // `api.Plugin.Defaults()` that understands how to parse a // `yaml.Node` that represents the top-level defaults object in the // scenario. for _, p := range plugins { @@ -84,35 +83,35 @@ func (s *Scenario) UnmarshalYAML(node *yaml.Node) error { } } // We store a lookup to the parsing plugin for each parsed test spec - evalPlugins := map[int]gdttypes.Plugin{} + evalPlugins := map[int]api.Plugin{} for i := 0; i < len(node.Content); i += 2 { keyNode := node.Content[i] if keyNode.Kind != yaml.ScalarNode { - return gdterrors.ExpectedScalarAt(keyNode) + return api.ExpectedScalarAt(keyNode) } key := keyNode.Value valNode := node.Content[i+1] switch key { case "tests": if valNode.Kind != yaml.SequenceNode { - return gdterrors.ExpectedSequenceAt(valNode) + return api.ExpectedSequenceAt(valNode) } for idx, testNode := range valNode.Content { parsed := false - base := gdttypes.Spec{} + base := api.Spec{} if err := testNode.Decode(&base); err != nil { return err } base.Index = idx base.Defaults = &defaults - pluginSpecs := map[gdttypes.Plugin][]gdttypes.Evaluable{} + pluginSpecs := map[api.Plugin][]api.Evaluable{} for _, p := range plugins { pluginSpecs[p] = p.Specs() } for plugin, specs := range pluginSpecs { for _, sp := range specs { if err := testNode.Decode(sp); err != nil { - if errors.Is(err, gdterrors.ErrUnknownField) { + if errors.Is(err, api.ErrUnknownField) { continue } return err @@ -125,28 +124,28 @@ func (s *Scenario) UnmarshalYAML(node *yaml.Node) error { } } if !parsed { - return gdterrors.UnknownSpecAt(s.Path, valNode) + return api.UnknownSpecAt(s.Path, valNode) } } case "skip-if": if valNode.Kind != yaml.SequenceNode { - return gdterrors.ExpectedSequenceAt(valNode) + return api.ExpectedSequenceAt(valNode) } for idx, testNode := range valNode.Content { parsed := false - base := gdttypes.Spec{} + base := api.Spec{} if err := testNode.Decode(&base); err != nil { return err } base.Index = idx base.Defaults = &defaults - specs := []gdttypes.Evaluable{} + specs := []api.Evaluable{} for _, p := range plugins { specs = append(specs, p.Specs()...) } for _, sp := range specs { if err := testNode.Decode(sp); err != nil { - if errors.Is(err, gdterrors.ErrUnknownField) { + if errors.Is(err, api.ErrUnknownField) { continue } return err @@ -157,7 +156,7 @@ func (s *Scenario) UnmarshalYAML(node *yaml.Node) error { break } if !parsed { - return gdterrors.UnknownSpecAt(s.Path, valNode) + return api.UnknownSpecAt(s.Path, valNode) } } } diff --git a/scenario/parse_test.go b/scenario/parse_test.go index 14bb855..76de4e0 100644 --- a/scenario/parse_test.go +++ b/scenario/parse_test.go @@ -9,9 +9,8 @@ import ( "path/filepath" "testing" - "github.com/gdt-dev/gdt/errors" + "github.com/gdt-dev/gdt/api" "github.com/gdt-dev/gdt/scenario" - gdttypes "github.com/gdt-dev/gdt/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -113,7 +112,7 @@ func TestBadTimeout(t *testing.T) { require.Nil(err) s, err := scenario.FromReader(f, scenario.WithPath(fp)) - assert.ErrorIs(err, errors.ErrExpectedScalarOrMap) + assert.ErrorIs(err, api.ErrExpectedScalarOrMap) assert.Nil(s) } @@ -152,7 +151,7 @@ func TestBadRetry(t *testing.T) { require.Nil(err) s, err := scenario.FromReader(f, scenario.WithPath(fp)) - assert.ErrorIs(err, errors.ErrExpectedMap) + assert.ErrorIs(err, api.ErrExpectedMap) assert.Nil(s) } @@ -165,7 +164,7 @@ func TestBadRetryAttempts(t *testing.T) { require.Nil(err) s, err := scenario.FromReader(f, scenario.WithPath(fp)) - assert.ErrorIs(err, errors.ErrInvalidRetryAttempts) + assert.ErrorIs(err, api.ErrInvalidRetryAttempts) assert.Nil(s) } @@ -212,7 +211,7 @@ func TestKnownSpec(t *testing.T) { }, s.Defaults, ) - expSpecDefaults := &gdttypes.Defaults{ + expSpecDefaults := &api.Defaults{ "foo": &fooDefaults{ fooInnerDefaults{ Bar: "barconfig", @@ -223,9 +222,9 @@ func TestKnownSpec(t *testing.T) { "priorRun": &priorRunDefaults{}, scenario.DefaultsKey: &scenario.Defaults{}, } - expTests := []gdttypes.Evaluable{ + expTests := []api.Evaluable{ &fooSpec{ - Spec: gdttypes.Spec{ + Spec: api.Spec{ Index: 0, Name: "bar", Defaults: expSpecDefaults, @@ -233,7 +232,7 @@ func TestKnownSpec(t *testing.T) { Foo: "bar", }, &fooSpec{ - Spec: gdttypes.Spec{ + Spec: api.Spec{ Index: 1, Description: "Bazzy Bizzy", Defaults: expSpecDefaults, @@ -259,18 +258,18 @@ func TestMultipleSpec(t *testing.T) { assert.IsType(&scenario.Scenario{}, s) assert.Equal("foo-bar", s.Name) assert.Equal(filepath.Join("testdata", "foo-bar.yaml"), s.Path) - expTests := []gdttypes.Evaluable{ + expTests := []api.Evaluable{ &fooSpec{ - Spec: gdttypes.Spec{ + Spec: api.Spec{ Index: 0, - Defaults: &gdttypes.Defaults{}, + Defaults: &api.Defaults{}, }, Foo: "bar", }, &barSpec{ - Spec: gdttypes.Spec{ + Spec: api.Spec{ Index: 1, - Defaults: &gdttypes.Defaults{}, + Defaults: &api.Defaults{}, }, Bar: 42, }, @@ -312,7 +311,7 @@ func TestEnvExpansion(t *testing.T) { }, s.Defaults, ) - expSpecDefaults := &gdttypes.Defaults{ + expSpecDefaults := &api.Defaults{ "foo": &fooDefaults{ fooInnerDefaults{ Bar: "barconfig", @@ -323,9 +322,9 @@ func TestEnvExpansion(t *testing.T) { "priorRun": &priorRunDefaults{}, scenario.DefaultsKey: &scenario.Defaults{}, } - expTests := []gdttypes.Evaluable{ + expTests := []api.Evaluable{ &fooSpec{ - Spec: gdttypes.Spec{ + Spec: api.Spec{ Index: 0, Name: "$NOT_EXPANDED", Defaults: expSpecDefaults, @@ -333,7 +332,7 @@ func TestEnvExpansion(t *testing.T) { Foo: "bar", }, &fooSpec{ - Spec: gdttypes.Spec{ + Spec: api.Spec{ Index: 1, Description: "Bazzy Bizzy", Defaults: expSpecDefaults, @@ -367,37 +366,37 @@ func TestScenarioDefaults(t *testing.T) { "fail": &failDefaults{failInnerDefaults{}}, "priorRun": &priorRunDefaults{}, scenario.DefaultsKey: &scenario.Defaults{ - Timeout: &gdttypes.Timeout{ + Timeout: &api.Timeout{ After: "2s", }, }, }, s.Defaults, ) - expSpecDefaults := &gdttypes.Defaults{ + expSpecDefaults := &api.Defaults{ "foo": &fooDefaults{}, "bar": &barDefaults{}, "fail": &failDefaults{failInnerDefaults{}}, "priorRun": &priorRunDefaults{}, scenario.DefaultsKey: &scenario.Defaults{ - Timeout: &gdttypes.Timeout{ + Timeout: &api.Timeout{ After: "2s", }, }, } - expTests := []gdttypes.Evaluable{ + expTests := []api.Evaluable{ &fooSpec{ - Spec: gdttypes.Spec{ + Spec: api.Spec{ Index: 0, Defaults: expSpecDefaults, - Timeout: &gdttypes.Timeout{ + Timeout: &api.Timeout{ After: "1s", }, }, Foo: "baz", }, &fooSpec{ - Spec: gdttypes.Spec{ + Spec: api.Spec{ Index: 1, Defaults: expSpecDefaults, }, diff --git a/scenario/run.go b/scenario/run.go index 35bb607..a6e37fb 100644 --- a/scenario/run.go +++ b/scenario/run.go @@ -14,15 +14,13 @@ import ( "github.com/cenkalti/backoff" + "github.com/gdt-dev/gdt/api" gdtcontext "github.com/gdt-dev/gdt/context" "github.com/gdt-dev/gdt/debug" - gdterrors "github.com/gdt-dev/gdt/errors" - "github.com/gdt-dev/gdt/result" - gdttypes "github.com/gdt-dev/gdt/types" ) // Run executes the scenario. The error that is returned will always be derived -// from `gdterrors.RuntimeError` and represents an *unrecoverable* error. +// from `api.RuntimeError` and represents an *unrecoverable* error. // // Test assertion failures are *not* considered errors. The Scenario.Run() // method controls whether `testing.T.Fail()` or `testing.T.Skip()` is called @@ -35,7 +33,7 @@ func (s *Scenario) Run(ctx context.Context, t *testing.T) error { lookup := strings.ToLower(fname) fix, found := fixtures[lookup] if !found { - return gdterrors.RequiredFixtureMissing(fname) + return api.RequiredFixtureMissing(fname) } if err := fix.Start(ctx); err != nil { return err @@ -120,11 +118,11 @@ func (s *Scenario) Run(ctx context.Context, t *testing.T) error { // runSpec executes an individual test spec func (s *Scenario) runSpec( ctx context.Context, - retry *gdttypes.Retry, - timeout *gdttypes.Timeout, + retry *api.Retry, + timeout *api.Timeout, idx int, - spec gdttypes.Evaluable, -) (*result.Result, error) { + spec api.Evaluable, +) (*api.Result, error) { sb := spec.Base() specTraceMsg := strconv.Itoa(idx) if sb.Name != "" { @@ -134,7 +132,7 @@ func (s *Scenario) runSpec( defer func() { ctx = gdtcontext.PopTrace(ctx) }() - if retry == nil || retry == gdttypes.NoRetry { + if retry == nil || retry == api.NoRetry { // Just evaluate the test spec once res, err := spec.Eval(ctx) if err != nil { @@ -150,7 +148,7 @@ func (s *Scenario) runSpec( // retry the action and test the assertions until they succeed, // there is a terminal failure, or the timeout expires. var bo backoff.BackOff - var res *result.Result + var res *api.Result var err error if retry.Exponential { @@ -159,7 +157,7 @@ func (s *Scenario) runSpec( ctx, ) } else { - interval := gdttypes.DefaultRetryConstantInterval + interval := api.DefaultRetryConstantInterval if retry.Interval != "" { interval = retry.IntervalDuration() } @@ -221,9 +219,9 @@ func (s *Scenario) runSpec( func getTimeout( ctx context.Context, scenDefaults *Defaults, - plugin gdttypes.Plugin, - eval gdttypes.Evaluable, -) *gdttypes.Timeout { + plugin api.Plugin, + eval api.Evaluable, +) *api.Timeout { evalTimeout := eval.Timeout() if evalTimeout != nil { debug.Println( @@ -274,12 +272,12 @@ func getTimeout( func getRetry( ctx context.Context, scenDefaults *Defaults, - plugin gdttypes.Plugin, - eval gdttypes.Evaluable, -) *gdttypes.Retry { + plugin api.Plugin, + eval api.Evaluable, +) *api.Retry { evalRetry := eval.Retry() if evalRetry != nil { - if evalRetry == gdttypes.NoRetry { + if evalRetry == api.NoRetry { return evalRetry } msg := "using retry" @@ -297,7 +295,7 @@ func getRetry( sb := eval.Base() baseRetry := sb.Retry if baseRetry != nil { - if baseRetry == gdttypes.NoRetry { + if baseRetry == api.NoRetry { return baseRetry } msg := "using retry" @@ -314,7 +312,7 @@ func getRetry( if scenDefaults != nil && scenDefaults.Retry != nil { scenRetry := scenDefaults.Retry - if scenRetry == gdttypes.NoRetry { + if scenRetry == api.NoRetry { return scenRetry } msg := "using retry" @@ -333,7 +331,7 @@ func getRetry( pluginRetry := pluginInfo.Retry if pluginRetry != nil { - if pluginRetry == gdttypes.NoRetry { + if pluginRetry == api.NoRetry { return pluginRetry } msg := "using retry" diff --git a/scenario/run_test.go b/scenario/run_test.go index 92c8ab3..c458d93 100644 --- a/scenario/run_test.go +++ b/scenario/run_test.go @@ -14,8 +14,8 @@ import ( "path/filepath" "testing" + "github.com/gdt-dev/gdt/api" gdtcontext "github.com/gdt-dev/gdt/context" - gdterrors "github.com/gdt-dev/gdt/errors" "github.com/gdt-dev/gdt/scenario" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -68,8 +68,8 @@ func TestMissingFixtures(t *testing.T) { // Pass a context with no fixtures registered... err = s.Run(context.TODO(), t) assert.NotNil(err) - assert.ErrorIs(err, gdterrors.ErrRequiredFixture) - assert.ErrorIs(err, gdterrors.RuntimeError) + assert.ErrorIs(err, api.ErrRequiredFixture) + assert.ErrorIs(err, api.RuntimeError) } func TestFixtureStartError(t *testing.T) { diff --git a/scenario/scenario.go b/scenario/scenario.go index 18716e2..c12b337 100644 --- a/scenario/scenario.go +++ b/scenario/scenario.go @@ -7,7 +7,7 @@ package scenario import ( gopath "path" - gdttypes "github.com/gdt-dev/gdt/types" + "github.com/gdt-dev/gdt/api" ) // Scenario is a generalized gdt test case file. It contains a set of Runnable @@ -15,7 +15,7 @@ import ( type Scenario struct { // evalPlugins stores the plugin that will evaluate the test spec at a // particular index - evalPlugins map[int]gdttypes.Plugin + evalPlugins map[int]api.Plugin // Path is the filepath to the test case. Path string `yaml:"-"` // Name is the short name for the test case. If empty, defaults to the base @@ -72,10 +72,10 @@ type Scenario struct { // // With the above, if an 'nginx' deployment exists already, the scenario // will skip all the tests. - SkipIf []gdttypes.Evaluable `yaml:"skip-if,omitempty"` + SkipIf []api.Evaluable `yaml:"skip-if,omitempty"` // Tests is the collection of test units in this test case. These will be // the fully parsed and materialized plugin Spec structs. - Tests []gdttypes.Evaluable `yaml:"tests,omitempty"` + Tests []api.Evaluable `yaml:"tests,omitempty"` } // Title returns the Name of the scenario or the Path's file/base name if there diff --git a/scenario/stub_plugins_test.go b/scenario/stub_plugins_test.go index 181c3db..d11954e 100644 --- a/scenario/stub_plugins_test.go +++ b/scenario/stub_plugins_test.go @@ -9,13 +9,11 @@ import ( "fmt" "strconv" + "github.com/gdt-dev/gdt/api" + gdtapi "github.com/gdt-dev/gdt/api" gdtcontext "github.com/gdt-dev/gdt/context" "github.com/gdt-dev/gdt/debug" - "github.com/gdt-dev/gdt/errors" - gdterrors "github.com/gdt-dev/gdt/errors" "github.com/gdt-dev/gdt/plugin" - "github.com/gdt-dev/gdt/result" - gdttypes "github.com/gdt-dev/gdt/types" "github.com/samber/lo" "gopkg.in/yaml.v3" ) @@ -37,28 +35,28 @@ type failDefaults struct { func (d *failDefaults) UnmarshalYAML(node *yaml.Node) error { if node.Kind != yaml.MappingNode { - return errors.ExpectedMapAt(node) + return api.ExpectedMapAt(node) } // maps/structs are stored in a top-level Node.Content field which is a // concatenated slice of Node pointers in pairs of key/values. for i := 0; i < len(node.Content); i += 2 { keyNode := node.Content[i] if keyNode.Kind != yaml.ScalarNode { - return errors.ExpectedScalarAt(keyNode) + return api.ExpectedScalarAt(keyNode) } key := keyNode.Value valNode := node.Content[i+1] switch key { case "fail": if valNode.Kind != yaml.MappingNode { - return errors.ExpectedMapAt(valNode) + return api.ExpectedMapAt(valNode) } inner := failInnerDefaults{} if err := valNode.Decode(&inner); err != nil { return err } d.failInnerDefaults = inner - // This is just for testing errors when parsing defaults... + // This is just for testing api when parsing defaults... if d.Fail { return fmt.Errorf("defaults parsing failed") } @@ -70,57 +68,57 @@ func (d *failDefaults) UnmarshalYAML(node *yaml.Node) error { } type failSpec struct { - gdttypes.Spec + api.Spec Fail bool `yaml:"fail"` } -func (s *failSpec) SetBase(b gdttypes.Spec) { +func (s *failSpec) SetBase(b api.Spec) { s.Spec = b } -func (s *failSpec) Base() *gdttypes.Spec { +func (s *failSpec) Base() *api.Spec { return &s.Spec } -func (s *failSpec) Retry() *gdttypes.Retry { +func (s *failSpec) Retry() *api.Retry { return nil } -func (s *failSpec) Timeout() *gdttypes.Timeout { +func (s *failSpec) Timeout() *api.Timeout { return nil } -func (s *failSpec) Eval(context.Context) (*result.Result, error) { - return nil, fmt.Errorf("%w: Indy, bad dates!", gdterrors.RuntimeError) +func (s *failSpec) Eval(context.Context) (*api.Result, error) { + return nil, fmt.Errorf("%w: Indy, bad dates!", gdtapi.RuntimeError) } func (s *failSpec) UnmarshalYAML(node *yaml.Node) error { if node.Kind != yaml.MappingNode { - return errors.ExpectedMapAt(node) + return api.ExpectedMapAt(node) } // maps/structs are stored in a top-level Node.Content field which is a // concatenated slice of Node pointers in pairs of key/values. for i := 0; i < len(node.Content); i += 2 { keyNode := node.Content[i] if keyNode.Kind != yaml.ScalarNode { - return errors.ExpectedScalarAt(keyNode) + return api.ExpectedScalarAt(keyNode) } key := keyNode.Value valNode := node.Content[i+1] switch key { case "fail": if valNode.Kind != yaml.ScalarNode { - return errors.ExpectedScalarAt(valNode) + return api.ExpectedScalarAt(valNode) } s.Fail, _ = strconv.ParseBool(valNode.Value) if s.Fail { return fmt.Errorf("Indy, bad parse!") } default: - if lo.Contains(gdttypes.BaseSpecFields, key) { + if lo.Contains(api.BaseSpecFields, key) { continue } - return errors.UnknownFieldAt(key, keyNode) + return api.UnknownFieldAt(key, keyNode) } } return nil @@ -128,8 +126,8 @@ func (s *failSpec) UnmarshalYAML(node *yaml.Node) error { type failingPlugin struct{} -func (p *failingPlugin) Info() gdttypes.PluginInfo { - return gdttypes.PluginInfo{ +func (p *failingPlugin) Info() api.PluginInfo { + return api.PluginInfo{ Name: "fail", } } @@ -138,8 +136,8 @@ func (p *failingPlugin) Defaults() yaml.Unmarshaler { return &failDefaults{} } -func (p *failingPlugin) Specs() []gdttypes.Evaluable { - return []gdttypes.Evaluable{&failSpec{}} +func (p *failingPlugin) Specs() []api.Evaluable { + return []api.Evaluable{&failSpec{}} } type fooInnerDefaults struct { @@ -152,21 +150,21 @@ type fooDefaults struct { func (d *fooDefaults) UnmarshalYAML(node *yaml.Node) error { if node.Kind != yaml.MappingNode { - return errors.ExpectedMapAt(node) + return api.ExpectedMapAt(node) } // maps/structs are stored in a top-level Node.Content field which is a // concatenated slice of Node pointers in pairs of key/values. for i := 0; i < len(node.Content); i += 2 { keyNode := node.Content[i] if keyNode.Kind != yaml.ScalarNode { - return errors.ExpectedScalarAt(keyNode) + return api.ExpectedScalarAt(keyNode) } key := keyNode.Value valNode := node.Content[i+1] switch key { case "foo": if valNode.Kind != yaml.MappingNode { - return errors.ExpectedMapAt(valNode) + return api.ExpectedMapAt(valNode) } inner := fooInnerDefaults{} if err := valNode.Decode(&inner); err != nil { @@ -181,56 +179,56 @@ func (d *fooDefaults) UnmarshalYAML(node *yaml.Node) error { } type fooSpec struct { - gdttypes.Spec + api.Spec Foo string `yaml:"foo"` } -func (s *fooSpec) SetBase(b gdttypes.Spec) { +func (s *fooSpec) SetBase(b api.Spec) { s.Spec = b } -func (s *fooSpec) Base() *gdttypes.Spec { +func (s *fooSpec) Base() *api.Spec { return &s.Spec } -func (s *fooSpec) Retry() *gdttypes.Retry { +func (s *fooSpec) Retry() *api.Retry { return nil } -func (s *fooSpec) Timeout() *gdttypes.Timeout { +func (s *fooSpec) Timeout() *api.Timeout { return nil } func (s *fooSpec) UnmarshalYAML(node *yaml.Node) error { if node.Kind != yaml.MappingNode { - return errors.ExpectedMapAt(node) + return api.ExpectedMapAt(node) } // maps/structs are stored in a top-level Node.Content field which is a // concatenated slice of Node pointers in pairs of key/values. for i := 0; i < len(node.Content); i += 2 { keyNode := node.Content[i] if keyNode.Kind != yaml.ScalarNode { - return errors.ExpectedScalarAt(keyNode) + return api.ExpectedScalarAt(keyNode) } key := keyNode.Value valNode := node.Content[i+1] switch key { case "foo": if valNode.Kind != yaml.ScalarNode { - return errors.ExpectedScalarAt(valNode) + return api.ExpectedScalarAt(valNode) } s.Foo = valNode.Value default: - if lo.Contains(gdttypes.BaseSpecFields, key) { + if lo.Contains(api.BaseSpecFields, key) { continue } - return errors.UnknownFieldAt(key, keyNode) + return api.UnknownFieldAt(key, keyNode) } } return nil } -func (s *fooSpec) Eval(ctx context.Context) (*result.Result, error) { +func (s *fooSpec) Eval(ctx context.Context) (*api.Result, error) { fails := []error{} debug.Println(ctx, "in %s Foo=%s", s.Title(), s.Foo) // This is just a silly test to demonstrate how to write Eval() methods @@ -242,13 +240,13 @@ func (s *fooSpec) Eval(ctx context.Context) (*result.Result, error) { fail := fmt.Errorf("expected s.Foo = 'baz', got %s", s.Foo) fails = append(fails, fail) } - return result.New(result.WithFailures(fails...)), nil + return api.NewResult(api.WithFailures(fails...)), nil } type fooPlugin struct{} -func (p *fooPlugin) Info() gdttypes.PluginInfo { - return gdttypes.PluginInfo{ +func (p *fooPlugin) Info() api.PluginInfo { + return api.PluginInfo{ Name: "foo", } } @@ -257,8 +255,8 @@ func (p *fooPlugin) Defaults() yaml.Unmarshaler { return &fooDefaults{} } -func (p *fooPlugin) Specs() []gdttypes.Evaluable { - return []gdttypes.Evaluable{&fooSpec{}} +func (p *fooPlugin) Specs() []api.Evaluable { + return []api.Evaluable{&fooSpec{}} } type barDefaults struct { @@ -270,58 +268,58 @@ func (d *barDefaults) UnmarshalYAML(node *yaml.Node) error { } type barSpec struct { - gdttypes.Spec + api.Spec Bar int `yaml:"bar"` } -func (s *barSpec) SetBase(b gdttypes.Spec) { +func (s *barSpec) SetBase(b api.Spec) { s.Spec = b } -func (s *barSpec) Base() *gdttypes.Spec { +func (s *barSpec) Base() *api.Spec { return &s.Spec } -func (s *barSpec) Retry() *gdttypes.Retry { - return gdttypes.NoRetry +func (s *barSpec) Retry() *api.Retry { + return api.NoRetry } -func (s *barSpec) Timeout() *gdttypes.Timeout { +func (s *barSpec) Timeout() *api.Timeout { return nil } -func (s *barSpec) Eval(context.Context) (*result.Result, error) { - return result.New(), nil +func (s *barSpec) Eval(context.Context) (*api.Result, error) { + return api.NewResult(), nil } func (s *barSpec) UnmarshalYAML(node *yaml.Node) error { if node.Kind != yaml.MappingNode { - return errors.ExpectedMapAt(node) + return api.ExpectedMapAt(node) } // maps/structs are stored in a top-level Node.Content field which is a // concatenated slice of Node pointers in pairs of key/values. for i := 0; i < len(node.Content); i += 2 { keyNode := node.Content[i] if keyNode.Kind != yaml.ScalarNode { - return errors.ExpectedScalarAt(keyNode) + return api.ExpectedScalarAt(keyNode) } key := keyNode.Value valNode := node.Content[i+1] switch key { case "bar": if valNode.Kind != yaml.ScalarNode { - return errors.ExpectedScalarAt(valNode) + return api.ExpectedScalarAt(valNode) } if v, err := strconv.Atoi(valNode.Value); err != nil { - return errors.ExpectedIntAt(valNode) + return api.ExpectedIntAt(valNode) } else { s.Bar = v } default: - if lo.Contains(gdttypes.BaseSpecFields, key) { + if lo.Contains(api.BaseSpecFields, key) { continue } - return errors.UnknownFieldAt(key, keyNode) + return api.UnknownFieldAt(key, keyNode) } } return nil @@ -329,8 +327,8 @@ func (s *barSpec) UnmarshalYAML(node *yaml.Node) error { type barPlugin struct{} -func (p *barPlugin) Info() gdttypes.PluginInfo { - return gdttypes.PluginInfo{ +func (p *barPlugin) Info() api.PluginInfo { + return api.PluginInfo{ Name: "bar", } } @@ -339,8 +337,8 @@ func (p *barPlugin) Defaults() yaml.Unmarshaler { return &barDefaults{} } -func (p *barPlugin) Specs() []gdttypes.Evaluable { - return []gdttypes.Evaluable{&barSpec{}} +func (p *barPlugin) Specs() []api.Evaluable { + return []api.Evaluable{&barSpec{}} } const priorRunDataKey = "priorrun" @@ -352,62 +350,62 @@ func (d *priorRunDefaults) UnmarshalYAML(node *yaml.Node) error { } type priorRunSpec struct { - gdttypes.Spec + api.Spec State string `yaml:"state"` Prior string `yaml:"prior"` } -func (s *priorRunSpec) SetBase(b gdttypes.Spec) { +func (s *priorRunSpec) SetBase(b api.Spec) { s.Spec = b } -func (s *priorRunSpec) Base() *gdttypes.Spec { +func (s *priorRunSpec) Base() *api.Spec { return &s.Spec } -func (s *priorRunSpec) Retry() *gdttypes.Retry { +func (s *priorRunSpec) Retry() *api.Retry { return nil } -func (s *priorRunSpec) Timeout() *gdttypes.Timeout { +func (s *priorRunSpec) Timeout() *api.Timeout { return nil } func (s *priorRunSpec) UnmarshalYAML(node *yaml.Node) error { if node.Kind != yaml.MappingNode { - return errors.ExpectedMapAt(node) + return api.ExpectedMapAt(node) } // maps/structs are stored in a top-level Node.Content field which is a // concatenated slice of Node pointers in pairs of key/values. for i := 0; i < len(node.Content); i += 2 { keyNode := node.Content[i] if keyNode.Kind != yaml.ScalarNode { - return errors.ExpectedScalarAt(keyNode) + return api.ExpectedScalarAt(keyNode) } key := keyNode.Value valNode := node.Content[i+1] switch key { case "state": if valNode.Kind != yaml.ScalarNode { - return errors.ExpectedScalarAt(valNode) + return api.ExpectedScalarAt(valNode) } s.State = valNode.Value case "prior": if valNode.Kind != yaml.ScalarNode { - return errors.ExpectedScalarAt(valNode) + return api.ExpectedScalarAt(valNode) } s.Prior = valNode.Value default: - if lo.Contains(gdttypes.BaseSpecFields, key) { + if lo.Contains(api.BaseSpecFields, key) { continue } - return errors.UnknownFieldAt(key, keyNode) + return api.UnknownFieldAt(key, keyNode) } } return nil } -func (s *priorRunSpec) Eval(ctx context.Context) (*result.Result, error) { +func (s *priorRunSpec) Eval(ctx context.Context) (*api.Result, error) { // Here we test that the prior run data that we save at the end of each // Run() is showing up properly in the next Run()'s context. fails := []error{} @@ -425,16 +423,16 @@ func (s *priorRunSpec) Eval(ctx context.Context) (*result.Result, error) { fails = append(fails, fmt.Errorf("expected priorRunData == data")) } } - return result.New( - result.WithFailures(fails...), - result.WithData(priorRunDataKey, s.State), + return api.NewResult( + api.WithFailures(fails...), + api.WithData(priorRunDataKey, s.State), ), nil } type priorRunPlugin struct{} -func (p *priorRunPlugin) Info() gdttypes.PluginInfo { - return gdttypes.PluginInfo{ +func (p *priorRunPlugin) Info() api.PluginInfo { + return api.PluginInfo{ Name: "priorRun", } } @@ -443,6 +441,6 @@ func (p *priorRunPlugin) Defaults() yaml.Unmarshaler { return &priorRunDefaults{} } -func (p *priorRunPlugin) Specs() []gdttypes.Evaluable { - return []gdttypes.Evaluable{&priorRunSpec{}} +func (p *priorRunPlugin) Specs() []api.Evaluable { + return []api.Evaluable{&priorRunSpec{}} }