dashboard_provisioning_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package sqlstore
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/grafana/grafana/pkg/components/simplejson"
  6. "github.com/grafana/grafana/pkg/models"
  7. . "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestDashboardProvisioningTest(t *testing.T) {
  10. Convey("Testing Dashboard provisioning", t, func() {
  11. InitTestDB(t)
  12. saveDashboardCmd := &models.SaveDashboardCommand{
  13. OrgId: 1,
  14. FolderId: 0,
  15. IsFolder: false,
  16. Dashboard: simplejson.NewFromAny(map[string]interface{}{
  17. "id": nil,
  18. "title": "test dashboard",
  19. }),
  20. }
  21. Convey("Saving dashboards with extras", func() {
  22. now := time.Now()
  23. cmd := &models.SaveProvisionedDashboardCommand{
  24. DashboardCmd: saveDashboardCmd,
  25. DashboardProvisioning: &models.DashboardProvisioning{
  26. Name: "default",
  27. ExternalId: "/var/grafana.json",
  28. Updated: now.Unix(),
  29. },
  30. }
  31. err := SaveProvisionedDashboard(cmd)
  32. So(err, ShouldBeNil)
  33. So(cmd.Result, ShouldNotBeNil)
  34. So(cmd.Result.Id, ShouldNotEqual, 0)
  35. dashId := cmd.Result.Id
  36. Convey("Can query for provisioned dashboards", func() {
  37. query := &models.GetProvisionedDashboardDataQuery{Name: "default"}
  38. err := GetProvisionedDashboardDataQuery(query)
  39. So(err, ShouldBeNil)
  40. So(len(query.Result), ShouldEqual, 1)
  41. So(query.Result[0].DashboardId, ShouldEqual, dashId)
  42. So(query.Result[0].Updated, ShouldEqual, now.Unix())
  43. })
  44. })
  45. })
  46. }