fleet/server/service/service_hosts_test.go

80 lines
1.5 KiB
Go
Raw Normal View History

2016-09-26 18:48:55 +00:00
package service
import (
"context"
"testing"
"github.com/fleetdm/fleet/server/config"
"github.com/fleetdm/fleet/server/datastore/inmem"
"github.com/fleetdm/fleet/server/kolide"
"github.com/stretchr/testify/assert"
)
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())
assert.Nil(t, err)
svc, err := newTestService(ds, nil, nil)
assert.Nil(t, err)
ctx := context.Background()
hosts, err := svc.ListHosts(ctx, kolide.HostListOptions{})
assert.Nil(t, err)
assert.Len(t, hosts, 0)
_, err = ds.NewHost(&kolide.Host{
HostName: "foo",
})
assert.Nil(t, err)
hosts, err = svc.ListHosts(ctx, kolide.HostListOptions{})
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())
assert.Nil(t, err)
svc, err := newTestService(ds, nil, nil)
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())
assert.Nil(t, err)
svc, err := newTestService(ds, nil, nil)
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)
hosts, err := ds.ListHosts(kolide.HostListOptions{})
assert.Nil(t, err)
assert.Len(t, hosts, 0)
}