-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy patherrors_test.go
More file actions
60 lines (51 loc) · 1.51 KB
/
errors_test.go
File metadata and controls
60 lines (51 loc) · 1.51 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
package spec_test
import (
"errors"
"testing"
"github.com/oaswrap/spec"
"github.com/oaswrap/spec/internal/validate"
)
func TestValidationErrorAlias(t *testing.T) {
// Simulate an error returned from internal/validate
inner := errors.New("validation failed")
err := error(validate.Error{
Err: inner,
Severity: validate.SeverityWarning,
})
// Verify we can use the public alias and constants
var valErr spec.ValidationError
if !errors.As(err, &valErr) {
t.Fatal("expected error to be spec.ValidationError")
}
if valErr.Severity != spec.SeverityWarning {
t.Errorf("expected SeverityWarning, got %v", valErr.Severity)
}
if !errors.Is(valErr, inner) {
t.Error("expected ValidationError to wrap inner error")
}
}
func TestValidationErrors_HasSeverity(t *testing.T) {
vErrs := spec.ValidationErrors{
Errors: []spec.ValidationError{
{Err: errors.New("err"), Severity: spec.SeverityError},
{Err: errors.New("warn"), Severity: spec.SeverityWarning},
},
}
if !vErrs.HasSeverity(spec.SeverityError) {
t.Error("expected to have SeverityError")
}
if !vErrs.HasSeverity(spec.SeverityWarning) {
t.Error("expected to have SeverityWarning")
}
if vErrs.HasSeverity(spec.SeverityInfo) {
t.Error("expected NOT to have SeverityInfo")
}
vWarnsOnly := spec.ValidationErrors{
Errors: []spec.ValidationError{
{Err: errors.New("warn"), Severity: spec.SeverityWarning},
},
}
if vWarnsOnly.HasSeverity(spec.SeverityError) {
t.Error("expected NOT to have SeverityError in warnings-only collection")
}
}