forked from open-policy-agent/opa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors_test.go
41 lines (31 loc) · 999 Bytes
/
errors_test.go
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
// Copyright 2016 The OPA Authors. All rights reserved.
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.
package ast
import "testing"
func TestErrorsString(t *testing.T) {
err := Errors{
NewError(ParseErr, nil, "blah"),
NewError(ParseErr, NewLocation(nil, "", 100, 2), "bleh"),
NewError(ParseErr, NewLocation(nil, "foo.rego", 100, 2), "blarg"),
}
expected := `3 errors occurred:
rego_parse_error: blah
100:2: rego_parse_error: bleh
foo.rego:100: rego_parse_error: blarg`
result := err.Error()
if result != expected {
t.Errorf("Expected %v but got: %v", expected, result)
}
err = Errors{NewError(ParseErr, nil, "blah")}
expected = `1 error occurred: rego_parse_error: blah`
result = err.Error()
if result != expected {
t.Errorf("Expected %v but got: %v", expected, result)
}
expected = `no error(s)`
result = Errors{}.Error()
if result != expected {
t.Errorf("Expected %v but got: %v", expected, result)
}
}