Handle null resolution in host details (#2622)

* Handle null resolution in host details

* Add test for null resolution
This commit is contained in:
Tomas Touceda 2021-10-21 15:53:23 -03:00 committed by GitHub
parent 43ea04206e
commit bcf6697741
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -938,7 +938,7 @@ func (d *Datastore) ListPoliciesForHost(ctx context.Context, hid uint) (packs []
ELSE ''
END AS response,
q.description,
p.resolution
coalesce(p.resolution, '') as resolution
FROM (
SELECT * FROM policy_membership_history WHERE id IN (
SELECT max(id) AS id FROM policy_membership_history WHERE host_id=? GROUP BY host_id, policy_id

View File

@ -305,9 +305,17 @@ func testPolicyQueriesForHost(t *testing.T, ds *Datastore) {
require.NoError(t, ds.RecordPolicyQueryExecutions(
context.Background(), host2, map[uint]*bool{gp.ID: nil}, time.Now()))
// insert a null resolution
res, err := ds.writer.ExecContext(context.Background(), `INSERT INTO policies (query_id) VALUES (?)`, q.ID)
require.NoError(t, err)
id, err := res.LastInsertId()
require.NoError(t, err)
require.NoError(t, ds.RecordPolicyQueryExecutions(
context.Background(), host2, map[uint]*bool{uint(id): nil}, time.Now()))
policies, err = ds.ListPoliciesForHost(context.Background(), host2.ID)
require.NoError(t, err)
require.Len(t, policies, 1)
require.Len(t, policies, 2)
assert.Equal(t, "query1 desc", policies[0].QueryDescription)
assert.Equal(t, "some gp resolution", policies[0].Resolution)