fleet/server/service_sessions_test.go
Zachary Wasserman 885db1a597 Refactoring for config patterns (#159)
This PR refactors most of the codebase to use the new config patterns implemented in #149. Now the core service keeps a copy of the KolideConfig struct, and service methods can reference the configuration in that struct when they need it. The most significant refactoring is in the sessions code, separating the business logic from the storage layer.
2016-09-14 09:11:06 -07:00

36 lines
847 B
Go

package server
import (
"testing"
kitlog "github.com/go-kit/kit/log"
"github.com/kolide/kolide-ose/config"
"github.com/kolide/kolide-ose/datastore"
"github.com/kolide/kolide-ose/kolide"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)
const bcryptCost = 6
func TestAuthenticate(t *testing.T) {
ds, err := datastore.New("gorm-sqlite3", ":memory:")
assert.Nil(t, err)
svc, err := NewService(ds, kitlog.NewNopLogger(), config.TestConfig())
assert.Nil(t, err)
ctx := context.Background()
user, err := kolide.NewUser("foo", "bar", "foo@kolide.co", false, false, bcryptCost)
assert.Nil(t, err)
user, err = ds.NewUser(user)
assert.Nil(t, err)
assert.NotZero(t, user.ID)
loggedIn, token, err := svc.Login(ctx, "foo", "bar")
assert.Nil(t, err)
assert.Equal(t, user.ID, loggedIn.ID)
assert.NotEmpty(t, token)
}