Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Empty json output to array #46

Merged
merged 2 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/judge/rego.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (j *RegoJudge) Eval(input []map[string]interface{}) ([]Result, error) {
return nil, err
}

var results []Result
results := []Result{}
for _, r := range rs {
for _, e := range r.Expressions {
for _, i := range e.Value.([]interface{}) {
Expand Down
23 changes: 23 additions & 0 deletions pkg/judge/rego_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package judge

import (
"testing"
)

func TestEvalEmpty(t *testing.T) {
inputs := []map[string]interface{}{}

judge, err := NewRegoJudge(&RegoOpts{})
if err != nil {
t.Errorf("failed to create judge instance: %s", err)
}

results, err := judge.Eval(inputs)
if err != nil {
t.Errorf("failed to evaluate input: %s", err)
}

if results == nil || len(results) != 0 {
t.Errorf("expected empty array, instead got: %v", results)
}
}