Skip to content

Commit

Permalink
🐛 fix computed filters after compile (#1138)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-rock authored Apr 6, 2023
1 parent c613c65 commit 0597f66
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions explorer/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ func (p *Bundle) Compile(ctx context.Context) (*BundleMap, error) {
if err = pack.Filters.Compile(ownerMrn); err != nil {
return nil, errors.Wrap(err, "failed to compile querypack filters")
}
pack.ComputedFilters.AddFilters(pack.Filters)

if err := cache.compileQueries(pack.Queries, pack); err != nil {
return nil, err
Expand Down
15 changes: 15 additions & 0 deletions explorer/filters_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package explorer

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -41,3 +42,17 @@ func TestSummarize(t *testing.T) {
assert.Equal(t, "asset.name, filter 2", f.Summarize())
})
}

func TestBundleAssetFilter(t *testing.T) {
// load the raw bundle
bundle, err := BundleFromPaths("../examples/os.mql.yaml")
require.NoError(t, err)
assert.Equal(t, 1, len(bundle.Packs))
assert.Equal(t, "asset.family.contains(\"unix\")", bundle.Packs[0].Filters.Items["0"].Mql)
assert.Equal(t, (*Filters)(nil), bundle.Packs[0].ComputedFilters)

// check that the computed asset filters are set
pbm, err := bundle.Compile(context.Background())
require.NoError(t, err)
assert.Equal(t, "asset.family.contains(\"unix\")", pbm.Packs["//local.cnquery.io/run/local-execution/querypacks/linux-mixed-queries"].ComputedFilters.Summarize())
}

0 comments on commit 0597f66

Please sign in to comment.