2
2
//
3
3
// See the COPYING file in the root project directory for full text.
4
4
5
- package errors
5
+ package api
6
6
7
7
import (
8
8
"errors"
@@ -11,6 +11,90 @@ import (
11
11
"gopkg.in/yaml.v3"
12
12
)
13
13
14
+ var (
15
+ // ErrFailure is the base error class for all errors that represent failed
16
+ // assertions when evaluating a test.
17
+ ErrFailure = errors .New ("assertion failed" )
18
+ // ErrTimeoutExceeded is an ErrFailure when a test's execution exceeds a
19
+ // timeout length.
20
+ ErrTimeoutExceeded = fmt .Errorf ("%s: timeout exceeded" , ErrFailure )
21
+ // ErrNotEqual is an ErrFailure when an expected thing doesn't equal an
22
+ // observed thing.
23
+ ErrNotEqual = fmt .Errorf ("%w: not equal" , ErrFailure )
24
+ // ErrIn is an ErrFailure when a thing unexpectedly appears in an
25
+ // container.
26
+ ErrIn = fmt .Errorf ("%w: in" , ErrFailure )
27
+ // ErrNotIn is an ErrFailure when an expected thing doesn't appear in an
28
+ // expected container.
29
+ ErrNotIn = fmt .Errorf ("%w: not in" , ErrFailure )
30
+ // ErrNoneIn is an ErrFailure when none of a list of elements appears in an
31
+ // expected container.
32
+ ErrNoneIn = fmt .Errorf ("%w: none in" , ErrFailure )
33
+ // ErrUnexpectedError is an ErrFailure when an unexpected error has
34
+ // occurred.
35
+ ErrUnexpectedError = fmt .Errorf ("%w: unexpected error" , ErrFailure )
36
+ )
37
+
38
+ // TimeoutExceeded returns an ErrTimeoutExceeded when a test's execution
39
+ // exceeds a timeout length. The optional failure parameter indicates a failed
40
+ // assertion that occurred before a timeout was reached.
41
+ func TimeoutExceeded (duration string , failure error ) error {
42
+ if failure != nil {
43
+ return fmt .Errorf (
44
+ "%w: timed out waiting for assertion to succeed (%s)" ,
45
+ failure , duration ,
46
+ )
47
+ }
48
+ return fmt .Errorf ("%s (%s)" , ErrTimeoutExceeded , duration )
49
+ }
50
+
51
+ // NotEqualLength returns an ErrNotEqual when an expected length doesn't
52
+ // equal an observed length.
53
+ func NotEqualLength (exp , got int ) error {
54
+ return fmt .Errorf (
55
+ "%w: expected length of %d but got %d" ,
56
+ ErrNotEqual , exp , got ,
57
+ )
58
+ }
59
+
60
+ // NotEqual returns an ErrNotEqual when an expected thing doesn't equal an
61
+ // observed thing.
62
+ func NotEqual (exp , got interface {}) error {
63
+ return fmt .Errorf ("%w: expected %v but got %v" , ErrNotEqual , exp , got )
64
+ }
65
+
66
+ // In returns an ErrIn when a thing unexpectedly appears in a container.
67
+ func In (element , container interface {}) error {
68
+ return fmt .Errorf (
69
+ "%w: expected %v not to contain %v" ,
70
+ ErrIn , container , element ,
71
+ )
72
+ }
73
+
74
+ // NotIn returns an ErrNotIn when an expected thing doesn't appear in an
75
+ // expected container.
76
+ func NotIn (element , container interface {}) error {
77
+ return fmt .Errorf (
78
+ "%w: expected %v to contain %v" ,
79
+ ErrNotIn , container , element ,
80
+ )
81
+ }
82
+
83
+ // NoneIn returns an ErrNoneIn when none of a list of elements appears in an
84
+ // expected container.
85
+ func NoneIn (elements , container interface {}) error {
86
+ return fmt .Errorf (
87
+ "%w: expected %v to contain one of %v" ,
88
+ ErrNoneIn , container , elements ,
89
+ )
90
+ }
91
+
92
+ // UnexpectedError returns an ErrUnexpectedError when a supplied error is not
93
+ // expected.
94
+ func UnexpectedError (err error ) error {
95
+ return fmt .Errorf ("%w: %s" , ErrUnexpectedError , err )
96
+ }
97
+
14
98
var (
15
99
// ErrUnknownSourceType indicates that a From() function was called with an
16
100
// unknown source parameter type.
@@ -199,3 +283,21 @@ func FileNotFound(path string, node *yaml.Node) error {
199
283
ErrFileNotFound , path , node .Line , node .Column ,
200
284
)
201
285
}
286
+
287
+ var (
288
+ // RuntimeError is the base error class for all errors occurring during
289
+ // runtime (and not during the parsing of a scenario or spec)
290
+ RuntimeError = errors .New ("runtime error" )
291
+ // ErrRequiredFixture is returned when a required fixture has not
292
+ // been registered with the context.
293
+ ErrRequiredFixture = fmt .Errorf (
294
+ "%w: required fixture missing" ,
295
+ RuntimeError ,
296
+ )
297
+ )
298
+
299
+ // RequiredFixtureMissing returns an ErrRequiredFixture with the supplied
300
+ // fixture name
301
+ func RequiredFixtureMissing (name string ) error {
302
+ return fmt .Errorf ("%w: %s" , ErrRequiredFixture , name )
303
+ }
0 commit comments