grafana/pkg/services/sqlstore/search_builder_test.go
Emil Tullstedt 55c306eb6d
Refactor search (#23550)
Co-Authored-By: Arve Knudsen <arve.knudsen@grafana.com>
Co-Authored-By: Leonard Gram <leonard.gram@grafana.com>
2020-04-20 16:20:45 +02:00

40 lines
1.2 KiB
Go

package sqlstore
import (
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
"testing"
"github.com/grafana/grafana/pkg/models"
. "github.com/smartystreets/goconvey/convey"
)
func TestSearchBuilder(t *testing.T) {
Convey("Testing building a search", t, func() {
if dialect == nil {
dialect = &migrator.Sqlite3{}
}
signedInUser := &models.SignedInUser{
OrgId: 1,
UserId: 1,
}
sb := NewSearchBuilder(signedInUser, 1000, 0, models.PERMISSION_VIEW)
Convey("When building a normal search", func() {
sql, params := sb.IsStarred().WithTitle("test").ToSql()
So(sql, ShouldStartWith, "SELECT")
So(sql, ShouldContainSubstring, "INNER JOIN dashboard on ids.id = dashboard.id")
So(sql, ShouldContainSubstring, "ORDER BY dashboard.title ASC")
So(len(params), ShouldBeGreaterThan, 0)
})
Convey("When building a search with tag filter", func() {
sql, params := sb.WithTags([]string{"tag1", "tag2"}).ToSql()
So(sql, ShouldStartWith, "SELECT")
So(sql, ShouldContainSubstring, "LEFT OUTER JOIN dashboard_tag")
So(sql, ShouldContainSubstring, "ORDER BY dashboard.title ASC")
So(len(params), ShouldBeGreaterThan, 0)
})
})
}