dashboards_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package sqlstore
  2. import (
  3. "testing"
  4. . "github.com/smartystreets/goconvey/convey"
  5. m "github.com/torkelo/grafana-pro/pkg/models"
  6. )
  7. func TestDashboardDataAccess(t *testing.T) {
  8. Convey("Testing DB", t, func() {
  9. InitTestDB(t)
  10. Convey("Given saved dashboard", func() {
  11. var savedDash *m.Dashboard
  12. cmd := m.SaveDashboardCommand{
  13. AccountId: 1,
  14. Dashboard: map[string]interface{}{
  15. "id": nil,
  16. "title": "test dash 23",
  17. "tags": make([]interface{}, 0),
  18. },
  19. }
  20. err := SaveDashboard(&cmd)
  21. So(err, ShouldBeNil)
  22. savedDash = cmd.Result
  23. Convey("Should return dashboard model", func() {
  24. So(savedDash.Title, ShouldEqual, "test dash 23")
  25. So(savedDash.Slug, ShouldEqual, "test-dash-23")
  26. So(savedDash.Id, ShouldNotEqual, 0)
  27. })
  28. Convey("Should be able to get dashboard", func() {
  29. query := m.GetDashboardQuery{
  30. Slug: "test-dash-23",
  31. AccountId: 1,
  32. }
  33. err := GetDashboard(&query)
  34. So(err, ShouldBeNil)
  35. So(query.Result.Title, ShouldEqual, "test dash 23")
  36. So(query.Result.Slug, ShouldEqual, "test-dash-23")
  37. })
  38. Convey("Should not be able to save dashboard with same name", func() {
  39. cmd := m.SaveDashboardCommand{
  40. AccountId: 1,
  41. Dashboard: map[string]interface{}{
  42. "id": nil,
  43. "title": "test dash 23",
  44. "tags": make([]interface{}, 0),
  45. },
  46. }
  47. err := SaveDashboard(&cmd)
  48. So(err, ShouldNotBeNil)
  49. })
  50. })
  51. })
  52. }