fleet/server/service/service_hosts_test.go
Mike Arpaia 704ddd424b Host summary endpoint (#742)
* Initial scaffolding of the host summary endpoint

* inmem datastore implementation of GenerateHostStatusStatistics

* HostSummary docstring

* changing the url of the host summary endpoint

* datastore tests for GenerateHostStatusStatistics

* MySQL datastore implementation of GenerateHostStatusStatistics

* <= and >= to catch exact time edge case

* removing clock interface method

* lowercase error wraps

* removin superfluous whitespace

* use updated_at

* adding a seen_at column to the hosts table

* moving the update of seen_time to the caller

* using db.Get instead of db.Select
2017-01-04 14:16:17 -07:00

80 lines
1.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 TestListHosts(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()
hosts, err := svc.ListHosts(ctx, kolide.ListOptions{})
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.ListOptions{})
assert.Nil(t, err)
assert.Len(t, hosts, 1)
}
func TestGetHost(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()
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) {
ds, err := inmem.New(config.TestConfig())
assert.Nil(t, err)
svc, err := newTestService(ds, 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.ListOptions{})
assert.Nil(t, err)
assert.Len(t, hosts, 0)
}