2016-09-26 18:48:55 +00:00
|
|
|
package service
|
2016-09-06 21:28:07 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2016-11-25 18:08:22 +00:00
|
|
|
"github.com/kolide/kolide-ose/server/config"
|
2016-11-16 13:47:49 +00:00
|
|
|
"github.com/kolide/kolide-ose/server/datastore/inmem"
|
2016-09-26 18:48:55 +00:00
|
|
|
"github.com/kolide/kolide-ose/server/kolide"
|
2016-09-06 21:28:07 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
2016-10-07 17:26:48 +00:00
|
|
|
func TestListHosts(t *testing.T) {
|
2016-11-25 18:08:22 +00:00
|
|
|
ds, err := inmem.New(config.TestConfig())
|
2016-09-06 21:28:07 +00:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2016-11-14 18:22:54 +00:00
|
|
|
svc, err := newTestService(ds, nil)
|
2016-09-06 21:28:07 +00:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2016-10-13 18:21:47 +00:00
|
|
|
hosts, err := svc.ListHosts(ctx, kolide.ListOptions{})
|
2016-09-06 21:28:07 +00:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Len(t, hosts, 0)
|
|
|
|
|
|
|
|
_, err = ds.NewHost(&kolide.Host{
|
|
|
|
HostName: "foo",
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2016-10-13 18:21:47 +00:00
|
|
|
hosts, err = svc.ListHosts(ctx, kolide.ListOptions{})
|
2016-09-06 21:28:07 +00:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Len(t, hosts, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetHost(t *testing.T) {
|
2016-11-25 18:08:22 +00:00
|
|
|
ds, err := inmem.New(config.TestConfig())
|
2016-09-06 21:28:07 +00:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2016-11-14 18:22:54 +00:00
|
|
|
svc, err := newTestService(ds, nil)
|
2016-09-06 21:28:07 +00:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
host, err := ds.NewHost(&kolide.Host{
|
|
|
|
HostName: "foo",
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotZero(t, host.ID)
|
|
|
|
|
|
|
|
hostVerify, err := svc.GetHost(ctx, host.ID)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, host.ID, hostVerify.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeleteHost(t *testing.T) {
|
2016-11-25 18:08:22 +00:00
|
|
|
ds, err := inmem.New(config.TestConfig())
|
2016-09-06 21:28:07 +00:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2016-11-14 18:22:54 +00:00
|
|
|
svc, err := newTestService(ds, nil)
|
2016-09-06 21:28:07 +00:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
host, err := ds.NewHost(&kolide.Host{
|
|
|
|
HostName: "foo",
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotZero(t, host.ID)
|
|
|
|
|
|
|
|
err = svc.DeleteHost(ctx, host.ID)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2016-10-14 15:59:27 +00:00
|
|
|
hosts, err := ds.ListHosts(kolide.ListOptions{})
|
2016-09-06 21:28:07 +00:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Len(t, hosts, 0)
|
|
|
|
|
|
|
|
}
|