fleet/server/service/service_packs_test.go
Mike Arpaia f109b14f9d Moving query attributes from the query object to the pack-query relationship (#559)
* 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
2016-12-13 14:22:05 -08:00

129 lines
2.5 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/stretchr/testify/assert"
"golang.org/x/net/context"
)
func TestListPacks(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()
queries, err := svc.ListPacks(ctx, kolide.ListOptions{})
assert.Nil(t, err)
assert.Len(t, queries, 0)
_, err = ds.NewPack(&kolide.Pack{
Name: "foo",
})
assert.Nil(t, err)
queries, err = svc.ListPacks(ctx, kolide.ListOptions{})
assert.Nil(t, err)
assert.Len(t, queries, 1)
}
func TestGetPack(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()
pack := &kolide.Pack{
Name: "foo",
}
_, err = ds.NewPack(pack)
assert.Nil(t, err)
assert.NotZero(t, pack.ID)
packVerify, err := svc.GetPack(ctx, pack.ID)
assert.Nil(t, err)
assert.Equal(t, pack.ID, packVerify.ID)
}
func TestNewPack(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()
name := "foo"
_, err = svc.NewPack(ctx, kolide.PackPayload{
Name: &name,
})
assert.Nil(t, err)
queries, err := ds.ListPacks(kolide.ListOptions{})
assert.Nil(t, err)
assert.Len(t, queries, 1)
}
func TestModifyPack(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()
pack := &kolide.Pack{
Name: "foo",
}
_, err = ds.NewPack(pack)
assert.Nil(t, err)
assert.NotZero(t, pack.ID)
newName := "bar"
packVerify, err := svc.ModifyPack(ctx, pack.ID, kolide.PackPayload{
Name: &newName,
})
assert.Nil(t, err)
assert.Equal(t, pack.ID, packVerify.ID)
assert.Equal(t, "bar", packVerify.Name)
}
func TestDeletePack(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()
pack := &kolide.Pack{
Name: "foo",
}
_, err = ds.NewPack(pack)
assert.Nil(t, err)
assert.NotZero(t, pack.ID)
err = svc.DeletePack(ctx, pack.ID)
assert.Nil(t, err)
queries, err := ds.ListPacks(kolide.ListOptions{})
assert.Nil(t, err)
assert.Len(t, queries, 0)
}