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

rego: Fix panic when partial evaluating w/ tracers #2011

Merged
merged 1 commit into from
Jan 22, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rego/rego.go
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,7 @@ func (r *Rego) partial(ctx context.Context, ectx *EvalContext) (*PartialQueries,
WithIndexing(ectx.indexing)

for i := range ectx.tracers {
q = q.WithTracer(r.tracers[i])
q = q.WithTracer(ectx.tracers[i])
}

if ectx.parsedInput != nil {
Expand Down
40 changes: 40 additions & 0 deletions rego/rego_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,46 @@ func TestPartialResultWithInput(t *testing.T) {
assertEval(t, r2, "[[true]]")
}

func TestPreparedPartialResultWithTracer(t *testing.T) {
mod := `
package test
default p = false
p {
input.x = 1
}
`
r := New(
Query("data.test.p == true"),
Module("test.rego", mod),
)

tracer := topdown.NewBufferTracer()

ctx := context.Background()
pq, err := r.PrepareForPartial(ctx)
if err != nil {
t.Fatalf("unexpected error from Rego.PrepareForPartial(): %s", err.Error())
}

pqs, err := pq.Partial(ctx, EvalTracer(tracer))
if err != nil {
t.Fatalf("unexpected error from PreparedEvalQuery.Partial(): %s", err.Error())
}

expectedQuery := "input.x = 1"
if len(pqs.Queries) != 1 {
t.Errorf("expected 1 query but found %d: %+v", len(pqs.Queries), pqs)
}
if pqs.Queries[0].String() != expectedQuery {
t.Errorf("unexpected query in result, expected='%s' found='%s'",
expectedQuery, pqs.Queries[0].String())
}

if len(*tracer) == 0 {
t.Errorf("Expected buffer tracer to contain > 0 traces")
}
}

func TestMissingLocation(t *testing.T) {

// Create a query programmatically and evaluate it. The Location information
Expand Down