-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.go
More file actions
64 lines (53 loc) · 1.48 KB
/
errors_test.go
File metadata and controls
64 lines (53 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package cortex_test
import (
"errors"
"testing"
"github.com/kolosys/cortex"
)
func TestRuleError(t *testing.T) {
baseErr := errors.New("base error")
ruleErr := cortex.NewRuleError("rule-1", "formula", "evaluate", baseErr)
expectedMsg := `cortex: rule "rule-1" (formula) evaluate: base error`
if ruleErr.Error() != expectedMsg {
t.Errorf("expected %q, got %q", expectedMsg, ruleErr.Error())
}
if !errors.Is(ruleErr, baseErr) {
t.Error("expected Unwrap to return base error")
}
}
func TestRuleErrorWithoutType(t *testing.T) {
baseErr := errors.New("base error")
ruleErr := cortex.NewRuleError("rule-1", "", "evaluate", baseErr)
expectedMsg := `cortex: rule "rule-1" evaluate: base error`
if ruleErr.Error() != expectedMsg {
t.Errorf("expected %q, got %q", expectedMsg, ruleErr.Error())
}
}
func TestSentinelErrors(t *testing.T) {
// Just verify they are defined and non-nil
sentinels := []error{
cortex.ErrRuleNotFound,
cortex.ErrLookupNotFound,
cortex.ErrKeyNotFound,
cortex.ErrValueNotFound,
cortex.ErrBuildupNotFound,
cortex.ErrInvalidRule,
cortex.ErrInvalidExpression,
cortex.ErrTypeMismatch,
cortex.ErrDivisionByZero,
cortex.ErrAllocationSum,
cortex.ErrCircularDep,
cortex.ErrEvaluation,
cortex.ErrShortCircuit,
cortex.ErrEngineClosed,
cortex.ErrTimeout,
cortex.ErrNilContext,
cortex.ErrDuplicateRule,
cortex.ErrDuplicateLookup,
}
for _, err := range sentinels {
if err == nil {
t.Error("expected non-nil sentinel error")
}
}
}