search_builder_test.go 1.1 KB

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