Skip to content

Commit

Permalink
🧹 Add test for filters (#1304)
Browse files Browse the repository at this point in the history
This tests shows, that MQL filters are OR connected.

Signed-off-by: Christian Zunker <christian@mondoo.com>
  • Loading branch information
czunker authored May 29, 2024
1 parent a04cc62 commit c37e9ec
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions policy/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1403,5 +1403,51 @@ queries:
qrIdToRj[rj.QrId] = rj
}
require.NotNil(t, qrIdToRj["root"])
}

func TestResolve_PoliciesMatchingFilters(t *testing.T) {
b := parseBundle(t, `
owner_mrn: //test.sth
policies:
- uid: policy1
groups:
- type: chapter
checks:
- uid: check1
- uid: check2
queries:
- uid: check1
title: check1
filters:
- mql: asset.name == "asset1"
- mql: asset.name == "asset2"
mql: |
asset.version
- uid: check2
title: check2
filters:
- mql: |
asset.name == "asset1"
asset.name == "asset2"
mql: |
asset.platform
`)

srv := initResolver(t, []*testAsset{
{asset: "asset1", policies: []string{policyMrn("policy1")}},
}, []*policy.Bundle{b})

t.Run("resolve with correct filters", func(t *testing.T) {
rp, err := srv.Resolve(context.Background(), &policy.ResolveReq{
PolicyMrn: "asset1",
AssetFilters: []*explorer.Mquery{{Mql: "asset.name == \"asset1\""}},
})
require.NoError(t, err)
require.NotNil(t, rp)

require.Len(t, rp.ExecutionJob.Queries, 1)
for _, v := range rp.ExecutionJob.Queries {
require.Equal(t, "asset.version\n", v.Query)
}
})
}

0 comments on commit c37e9ec

Please sign in to comment.