search_builder_test.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package sqlstore
  2. import (
  3. "testing"
  4. m "github.com/grafana/grafana/pkg/models"
  5. . "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestSearchBuilder(t *testing.T) {
  8. Convey("Testing building a search", t, func() {
  9. signedInUser := &m.SignedInUser{
  10. OrgId: 1,
  11. UserId: 1,
  12. }
  13. sb := NewSearchBuilder(signedInUser, 1000, 0, m.PERMISSION_VIEW)
  14. Convey("When building a normal search", func() {
  15. sql, params := sb.IsStarred().WithTitle("test").ToSql()
  16. So(sql, ShouldStartWith, "SELECT")
  17. So(sql, ShouldContainSubstring, "INNER JOIN dashboard on ids.id = dashboard.id")
  18. So(sql, ShouldContainSubstring, "ORDER BY dashboard.title ASC")
  19. So(len(params), ShouldBeGreaterThan, 0)
  20. })
  21. Convey("When building a search with tag filter", func() {
  22. sql, params := sb.WithTags([]string{"tag1", "tag2"}).ToSql()
  23. So(sql, ShouldStartWith, "SELECT")
  24. So(sql, ShouldContainSubstring, "LEFT OUTER JOIN dashboard_tag")
  25. So(sql, ShouldContainSubstring, "ORDER BY dashboard.title ASC")
  26. So(len(params), ShouldBeGreaterThan, 0)
  27. })
  28. })
  29. }