misc: Fix tests that relied on built-in errors

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
This commit is contained in:
Torin Sandall
2020-09-23 14:33:59 -04:00
committed by Patrick East
parent 9edab953c6
commit 8b93b5a976
4 changed files with 13 additions and 12 deletions
+2 -2
View File
@@ -32,7 +32,7 @@ func TestEvalExitCode(t *testing.T) {
}{
{"defined result", "true=true", true, false},
{"undefined result", "true = false", false, false},
{"on error", "x = 1/0", false, true},
{"on error", `{k: v | k = ["a", "a"][_]; v = [0,1][_]}`, false, true},
}
var b bytes.Buffer
@@ -204,7 +204,7 @@ func TestEvalWithInvalidInputFile(t *testing.T) {
func TestEvalReturnsRegoError(t *testing.T) {
buf := new(bytes.Buffer)
_, err := eval([]string{"1/0"}, newEvalCommandParams(), buf)
_, err := eval([]string{`{k: v | k = ["a", "a"][_]; v = [0,1][_]}`}, newEvalCommandParams(), buf)
if _, ok := err.(regoError); !ok {
t.Fatal("expected regoError but got:", err)
}
+2 -2
View File
@@ -551,10 +551,10 @@ func TestOptimizerErrors(t *testing.T) {
modules: map[string]string{
"test.rego": `
package test
p { div(1, 0, x) }
p { {k: v | k = ["a", "a"][_]; v = [0, 1][_] } }
`,
},
wantErr: fmt.Errorf("test.rego:3: eval_builtin_error: div: divide by zero"),
wantErr: fmt.Errorf("test.rego:3: eval_conflict_error: object keys must be unique"),
},
}
+5 -5
View File
@@ -39,12 +39,12 @@ func TestBasic(t *testing.T) {
allow = allow_inner {
not input.path[0] = "undefined" # testing undefined
not divide_by_zero # testing eval errors
not conflict_error # testing eval errors
}
divide_by_zero {
input.path[0] = "divide_by_zero"
x = 1 / 0
conflict_error {
input.path[0] = "conflict_error"
{k: v | k = ["a", "a"][_]; [1, 2][v]}
}
default allow_inner = false
@@ -142,7 +142,7 @@ func TestBasic(t *testing.T) {
{"root (ok)", "token0", http.MethodGet, "", http.StatusOK, "", ""},
{"index.html (ok)", "token0", http.MethodGet, "/index.html", http.StatusOK, "", ""},
{"undefined", "token0", http.MethodGet, "/undefined", http.StatusInternalServerError, types.CodeInternal, types.MsgUnauthorizedUndefinedError},
{"evaluation error", "token0", http.MethodGet, "/divide_by_zero", http.StatusInternalServerError, types.CodeInternal, types.MsgEvaluationError},
{"evaluation error", "token0", http.MethodGet, "/conflict_error", http.StatusInternalServerError, types.CodeInternal, types.MsgEvaluationError},
{"ok", "token1", http.MethodGet, "/data/some/specific/document", http.StatusOK, "", ""},
{"ok (w/ query params)", "token1", http.MethodGet, "/data/some/specific/document?pretty=true", http.StatusOK, "", ""},
{"unauthorized method", "token1", http.MethodPut, "/data/some/specific/document", http.StatusUnauthorized, types.CodeUnauthorized, types.MsgUnauthorizedError},
+4 -3
View File
@@ -2378,9 +2378,10 @@ func TestDecisionLogging(t *testing.T) {
response: `{"result": [{"x": {}}]}`,
},
{
method: "PUT",
path: "/policies/test2",
body: "package foo\np { 1/0 }",
method: "PUT",
path: "/policies/test2",
body: `package foo
p { {k: v | k = ["a", "a"][_]; v = [1, 2][_]} }`,
response: `{}`,
},
{