fleet/server/service/service_labels_test.go
Martin Angers 4f4185372d
Add support for context in datastore/mysql layer (#1962)
This is just to pass down the context to the datastore layer, it doesn't
use it just yet - this will be in a follow-up PR.
2021-09-14 08:11:07 -04:00

46 lines
1.1 KiB
Go

package service
import (
"context"
"testing"
"github.com/fleetdm/fleet/v4/server/datastore/mysql"
"github.com/fleetdm/fleet/v4/server/fleet"
"github.com/fleetdm/fleet/v4/server/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGetLabel(t *testing.T) {
ds := mysql.CreateMySQLDS(t)
defer ds.Close()
svc := newTestService(ds, nil, nil)
label := &fleet.Label{
Name: "foo",
Query: "select * from foo;",
}
label, err := ds.NewLabel(context.Background(), label)
assert.Nil(t, err)
assert.NotZero(t, label.ID)
labelVerify, err := svc.GetLabel(test.UserContext(test.UserAdmin), label.ID)
assert.Nil(t, err)
assert.Equal(t, label.ID, labelVerify.ID)
}
func TestGetLabels(t *testing.T) {
ds := mysql.CreateMySQLDS(t)
defer ds.Close()
require.NoError(t, ds.MigrateTables(context.Background()))
require.NoError(t, ds.MigrateData(context.Background()))
svc := newTestService(ds, nil, nil)
labels, err := svc.ListLabels(test.UserContext(test.UserAdmin), fleet.ListOptions{Page: 0, PerPage: 1000})
require.NoError(t, err)
require.Len(t, labels, 7)
}