mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-13 03:42:35 -06:00
039c7bdd02
- Refactor error codes to use strings instead of ints. - Simplify error messages throughout. - Ensure location set on all expressions. There were a couple locations in the parser/compiler where locations were not being set. - Fallback to rule location in topdown in case location not set. This ensures that users get useful locations for API requests with paths that refer to virtual docs exactly. Also add Find function to ast.Value. Useful for extracting values dynamically. Eventually can support JSON pointers. Fixes #237
42 lines
999 B
Go
42 lines
999 B
Go
// 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)
|
|
}
|
|
|
|
}
|