mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 01:15:22 +00:00
f109b14f9d
* Moving query attributes from the query object to the pack-query relationship * some additional tests * http request parsing test * QueryOptions in new test_util code * initial scaffolding of new request structures * service and datastore * test outline * l2 merge conflict scrub * service tests for scheduled query service * service and datastore tests * most endpoints and transports * order of values are not deterministic with inmem * transport tests * rename PackQuery to ScheduledQuery * removing existing implementation of adding queries to packs * accounting for the new argument to NewQuery * fix alignment in sql query * removing underscore * add removed to the datastore * removed differential from the schema
105 lines
3.3 KiB
Go
105 lines
3.3 KiB
Go
package service
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/kolide/kolide-ose/server/config"
|
|
"github.com/kolide/kolide-ose/server/datastore/inmem"
|
|
"github.com/kolide/kolide-ose/server/kolide"
|
|
"github.com/kolide/kolide-ose/server/test"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
func TestGetScheduledQueriesInPack(t *testing.T) {
|
|
ds, err := inmem.New(config.TestConfig())
|
|
assert.Nil(t, err)
|
|
svc, err := newTestService(ds, nil)
|
|
assert.Nil(t, err)
|
|
ctx := context.Background()
|
|
|
|
u1 := test.NewUser(t, ds, "Admin", "admin", "admin@kolide.co", true)
|
|
q1 := test.NewQuery(t, ds, "foo", "select * from time;", u1.ID, true)
|
|
q2 := test.NewQuery(t, ds, "bar", "select * from time;", u1.ID, true)
|
|
p1 := test.NewPack(t, ds, "baz")
|
|
sq1 := test.NewScheduledQuery(t, ds, p1.ID, q1.ID, 60, false, false)
|
|
|
|
queries, err := svc.GetScheduledQueriesInPack(ctx, p1.ID, kolide.ListOptions{})
|
|
require.Nil(t, err)
|
|
require.Len(t, queries, 1)
|
|
assert.Equal(t, sq1.ID, queries[0].ID)
|
|
|
|
test.NewScheduledQuery(t, ds, p1.ID, q2.ID, 60, false, false)
|
|
test.NewScheduledQuery(t, ds, p1.ID, q2.ID, 60, true, false)
|
|
|
|
queries, err = svc.GetScheduledQueriesInPack(ctx, p1.ID, kolide.ListOptions{})
|
|
require.Nil(t, err)
|
|
require.Len(t, queries, 3)
|
|
}
|
|
|
|
func TestGetScheduledQuery(t *testing.T) {
|
|
ds, err := inmem.New(config.TestConfig())
|
|
assert.Nil(t, err)
|
|
svc, err := newTestService(ds, nil)
|
|
assert.Nil(t, err)
|
|
ctx := context.Background()
|
|
|
|
u1 := test.NewUser(t, ds, "Admin", "admin", "admin@kolide.co", true)
|
|
q1 := test.NewQuery(t, ds, "foo", "select * from time;", u1.ID, true)
|
|
p1 := test.NewPack(t, ds, "baz")
|
|
sq1 := test.NewScheduledQuery(t, ds, p1.ID, q1.ID, 60, false, false)
|
|
|
|
query, err := svc.GetScheduledQuery(ctx, sq1.ID)
|
|
require.Nil(t, err)
|
|
assert.Equal(t, uint(60), query.Interval)
|
|
}
|
|
|
|
func TestModifyScheduledQuery(t *testing.T) {
|
|
ds, err := inmem.New(config.TestConfig())
|
|
assert.Nil(t, err)
|
|
svc, err := newTestService(ds, nil)
|
|
assert.Nil(t, err)
|
|
ctx := context.Background()
|
|
|
|
u1 := test.NewUser(t, ds, "Admin", "admin", "admin@kolide.co", true)
|
|
q1 := test.NewQuery(t, ds, "foo", "select * from time;", u1.ID, true)
|
|
p1 := test.NewPack(t, ds, "baz")
|
|
sq1 := test.NewScheduledQuery(t, ds, p1.ID, q1.ID, 60, false, false)
|
|
|
|
query, err := svc.GetScheduledQuery(ctx, sq1.ID)
|
|
require.Nil(t, err)
|
|
assert.Equal(t, uint(60), query.Interval)
|
|
|
|
query.Interval = uint(120)
|
|
query, err = svc.ModifyScheduledQuery(ctx, query)
|
|
assert.Equal(t, uint(120), query.Interval)
|
|
|
|
queryVerify, err := svc.GetScheduledQuery(ctx, sq1.ID)
|
|
require.Nil(t, err)
|
|
assert.Equal(t, uint(120), queryVerify.Interval)
|
|
}
|
|
|
|
func TestDeleteScheduledQuery(t *testing.T) {
|
|
ds, err := inmem.New(config.TestConfig())
|
|
assert.Nil(t, err)
|
|
svc, err := newTestService(ds, nil)
|
|
assert.Nil(t, err)
|
|
ctx := context.Background()
|
|
|
|
u1 := test.NewUser(t, ds, "Admin", "admin", "admin@kolide.co", true)
|
|
q1 := test.NewQuery(t, ds, "foo", "select * from time;", u1.ID, true)
|
|
p1 := test.NewPack(t, ds, "baz")
|
|
sq1 := test.NewScheduledQuery(t, ds, p1.ID, q1.ID, 60, false, false)
|
|
|
|
query, err := svc.GetScheduledQuery(ctx, sq1.ID)
|
|
require.Nil(t, err)
|
|
assert.Equal(t, uint(60), query.Interval)
|
|
|
|
err = svc.DeleteScheduledQuery(ctx, sq1.ID)
|
|
require.Nil(t, err)
|
|
|
|
_, err = svc.GetScheduledQuery(ctx, sq1.ID)
|
|
require.NotNil(t, err)
|
|
}
|