fleet/server/datastore/datastore_scheduled_queries_test.go
Zachary Wasserman 26dc30bd25
Update query and pack interfaces for fleetctl (#1670)
- Add new Apply spec methods for queries and packs
- Remove now extraneous datastore/service methods
- Remove import service (unused, and had many dependencies that this breaks)
- Refactor tests as appropriate
2018-01-03 11:18:05 -08:00

78 lines
2.0 KiB
Go

package datastore
import (
"testing"
"github.com/kolide/fleet/server/kolide"
"github.com/kolide/fleet/server/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func testListScheduledQueriesInPack(t *testing.T, ds kolide.Datastore) {
zwass := test.NewUser(t, ds, "Zach", "zwass", "zwass@kolide.co", true)
queries := []*kolide.Query{
{Name: "foo", Description: "get the foos", Query: "select * from foo"},
{Name: "bar", Description: "do some bars", Query: "select baz from bar"},
}
err := ds.ApplyQueries(zwass.ID, queries)
require.Nil(t, err)
specs := []*kolide.PackSpec{
&kolide.PackSpec{
Name: "baz",
Targets: kolide.PackSpecTargets{Labels: []string{}},
Queries: []kolide.PackSpecQuery{
kolide.PackSpecQuery{
QueryName: queries[0].Name,
Description: "test_foo",
Interval: 60,
},
},
},
}
err = ds.ApplyPackSpecs(specs)
require.Nil(t, err)
gotQueries, err := ds.ListScheduledQueriesInPack(1, kolide.ListOptions{})
require.Nil(t, err)
require.Len(t, gotQueries, 1)
assert.Equal(t, uint(60), gotQueries[0].Interval)
assert.Equal(t, "test_foo", gotQueries[0].Description)
assert.Equal(t, "select * from foo", gotQueries[0].Query)
boolPtr := func(b bool) *bool { return &b }
specs = []*kolide.PackSpec{
&kolide.PackSpec{
Name: "baz",
Targets: kolide.PackSpecTargets{Labels: []string{}},
Queries: []kolide.PackSpecQuery{
kolide.PackSpecQuery{
QueryName: queries[0].Name,
Description: "test_foo",
Interval: 60,
},
kolide.PackSpecQuery{
QueryName: queries[1].Name,
Name: "test bar",
Description: "test_bar",
Interval: 60,
},
kolide.PackSpecQuery{
QueryName: queries[1].Name,
Name: "test bar snapshot",
Description: "test_bar",
Interval: 60,
Snapshot: boolPtr(true),
},
},
},
}
err = ds.ApplyPackSpecs(specs)
require.Nil(t, err)
gotQueries, err = ds.ListScheduledQueriesInPack(1, kolide.ListOptions{})
require.Nil(t, err)
require.Len(t, gotQueries, 3)
}