dashboards_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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": []interface{}{"prod", "webapp"},
  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 be able to search for dashboard", func() {
  39. query := m.SearchDashboardsQuery{
  40. Query: "%test%",
  41. AccountId: 1,
  42. }
  43. err := SearchDashboards(&query)
  44. So(err, ShouldBeNil)
  45. So(len(query.Result), ShouldEqual, 1)
  46. })
  47. Convey("Should not be able to save dashboard with same name", func() {
  48. cmd := m.SaveDashboardCommand{
  49. AccountId: 1,
  50. Dashboard: map[string]interface{}{
  51. "id": nil,
  52. "title": "test dash 23",
  53. "tags": make([]interface{}, 0),
  54. },
  55. }
  56. err := SaveDashboard(&cmd)
  57. So(err, ShouldNotBeNil)
  58. })
  59. })
  60. })
  61. }