mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
7bb6dbe36b
Moving (most) source to v1 root package to prepare for v0/v1 API separation. Signed-off-by: Johan Fylling <johan.dev@fylling.se>
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)
|
|
}
|
|
|
|
}
|