mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 08:58:41 +00:00
Export fields so the select will work with the struct (#1819)
This commit is contained in:
parent
d6d53acda5
commit
2fd725c81b
2 changed files with 10 additions and 3 deletions
|
|
@ -106,8 +106,8 @@ func (ds *Datastore) DeleteGlobalPolicies(ids []uint) ([]uint, error) {
|
|||
|
||||
func (ds *Datastore) PolicyQueriesForHost(_ *fleet.Host) (map[string]string, error) {
|
||||
var rows []struct {
|
||||
id string `db:"id"`
|
||||
query string `db:"query"`
|
||||
Id string `db:"id"`
|
||||
Query string `db:"query"`
|
||||
}
|
||||
err := ds.db.Select(&rows, `SELECT p.id, q.query FROM policies p JOIN queries q ON (p.query_id=q.id)`)
|
||||
if err != nil {
|
||||
|
|
@ -117,7 +117,7 @@ func (ds *Datastore) PolicyQueriesForHost(_ *fleet.Host) (map[string]string, err
|
|||
results := map[string]string{}
|
||||
|
||||
for _, row := range rows {
|
||||
results[row.id] = row.query
|
||||
results[row.Id] = row.Query
|
||||
}
|
||||
|
||||
return results, nil
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package mysql
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -139,4 +140,10 @@ func TestPolicyMembershipView(t *testing.T) {
|
|||
policy, err := ds.Policy(policies[0].ID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, policies[0], policy)
|
||||
|
||||
queries, err := ds.PolicyQueriesForHost(nil)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, queries, 2)
|
||||
assert.Equal(t, q.Query, queries[fmt.Sprint(q.ID)])
|
||||
assert.Equal(t, q2.Query, queries[fmt.Sprint(q2.ID)])
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue