2014-08-21 22:09:48 +02:00
|
|
|
package stores
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
2014-08-22 15:32:42 +02:00
|
|
|
"github.com/dancannon/gorethink"
|
2014-08-21 22:09:48 +02:00
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
|
"github.com/torkelo/grafana-pro/pkg/models"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestRethinkStore(t *testing.T) {
|
2014-08-22 15:32:42 +02:00
|
|
|
store := NewRethinkStore(&RethinkCfg{DatabaseName: "tests"})
|
|
|
|
|
defer gorethink.DbDrop("tests").Exec(store.session)
|
2014-08-21 22:09:48 +02:00
|
|
|
|
|
|
|
|
Convey("Insert dashboard", t, func() {
|
|
|
|
|
dashboard := models.NewDashboard("test")
|
2014-08-22 15:32:42 +02:00
|
|
|
dashboard.AccountId = 1
|
2014-08-21 22:09:48 +02:00
|
|
|
|
|
|
|
|
err := store.SaveDashboard(dashboard)
|
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
So(dashboard.Id, ShouldNotBeEmpty)
|
|
|
|
|
|
2014-08-22 15:32:42 +02:00
|
|
|
read, err := store.GetDashboard("test", 1)
|
2014-08-21 22:09:48 +02:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
So(read, ShouldNotBeNil)
|
2014-08-22 15:32:42 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Convey("can get next account id", t, func() {
|
|
|
|
|
id, err := store.getNextAccountId()
|
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
So(id, ShouldNotEqual, 0)
|
|
|
|
|
|
|
|
|
|
id2, err := store.getNextAccountId()
|
|
|
|
|
So(id2, ShouldEqual, id+1)
|
|
|
|
|
})
|
2014-08-21 22:09:48 +02:00
|
|
|
|
2014-08-22 15:32:42 +02:00
|
|
|
Convey("can create account", t, func() {
|
2014-08-22 18:05:37 +02:00
|
|
|
account := &models.UserAccount{UserName: "torkelo", Email: "mupp", Login: "test@test.com"}
|
|
|
|
|
err := store.SaveUserAccount(account)
|
2014-08-22 15:32:42 +02:00
|
|
|
So(err, ShouldBeNil)
|
2014-08-22 18:05:37 +02:00
|
|
|
So(account.DatabaseId, ShouldNotEqual, 0)
|
|
|
|
|
|
|
|
|
|
read, err := store.GetUserAccountLogin("test@test.com")
|
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
So(read.DatabaseId, ShouldEqual, account.DatabaseId)
|
2014-08-22 15:32:42 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Convey("can get next dashboard id", t, func() {
|
2014-08-22 18:05:37 +02:00
|
|
|
account := &models.UserAccount{UserName: "torkelo", Email: "mupp"}
|
|
|
|
|
err := store.SaveUserAccount(account)
|
|
|
|
|
dashId, err := store.getNextDashboardNumber(account.DatabaseId)
|
2014-08-22 15:32:42 +02:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
So(dashId, ShouldEqual, 1)
|
2014-08-21 22:09:48 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|