rethinkdb_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package stores
  2. import (
  3. "testing"
  4. "github.com/dancannon/gorethink"
  5. . "github.com/smartystreets/goconvey/convey"
  6. "github.com/torkelo/grafana-pro/pkg/models"
  7. )
  8. func TestRethinkStore(t *testing.T) {
  9. store := NewRethinkStore(&RethinkCfg{DatabaseName: "tests"})
  10. defer gorethink.DbDrop("tests").Exec(store.session)
  11. Convey("Insert dashboard", t, func() {
  12. dashboard := models.NewDashboard("test")
  13. dashboard.AccountId = 1
  14. err := store.SaveDashboard(dashboard)
  15. So(err, ShouldBeNil)
  16. So(dashboard.Id, ShouldNotBeEmpty)
  17. read, err := store.GetDashboard("test", 1)
  18. So(err, ShouldBeNil)
  19. So(read, ShouldNotBeNil)
  20. })
  21. Convey("can get next account id", t, func() {
  22. id, err := store.getNextAccountId()
  23. So(err, ShouldBeNil)
  24. So(id, ShouldNotEqual, 0)
  25. id2, err := store.getNextAccountId()
  26. So(id2, ShouldEqual, id+1)
  27. })
  28. Convey("can create account", t, func() {
  29. account, err := store.createAccount()
  30. So(err, ShouldBeNil)
  31. So(account, ShouldNotBeNil)
  32. So(account.Id, ShouldNotEqual, 0)
  33. })
  34. Convey("can get next dashboard id", t, func() {
  35. account, err := store.createAccount()
  36. dashId, err := store.getNextDashboardNumber(account.Id)
  37. So(err, ShouldBeNil)
  38. So(dashId, ShouldEqual, 1)
  39. })
  40. }