dashboard_provisioning_test.go 1.3 KB

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