user_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package sqlstore
  2. import (
  3. "fmt"
  4. "testing"
  5. . "github.com/smartystreets/goconvey/convey"
  6. "github.com/grafana/grafana/pkg/models"
  7. )
  8. func TestUserDataAccess(t *testing.T) {
  9. Convey("Testing DB", t, func() {
  10. InitTestDB(t)
  11. var err error
  12. for i := 0; i < 5; i++ {
  13. err = CreateUser(&models.CreateUserCommand{
  14. Email: fmt.Sprint("user", i, "@test.com"),
  15. Name: fmt.Sprint("user", i),
  16. Login: fmt.Sprint("user", i),
  17. })
  18. So(err, ShouldBeNil)
  19. }
  20. Convey("Can return the first page of users and a total count", func() {
  21. query := models.SearchUsersQuery{Query: "", Page: 1, Limit: 3}
  22. err = SearchUsers(&query)
  23. So(err, ShouldBeNil)
  24. So(len(query.Result.Users), ShouldEqual, 3)
  25. So(query.Result.TotalCount, ShouldEqual, 5)
  26. })
  27. Convey("Can return the second page of users and a total count", func() {
  28. query := models.SearchUsersQuery{Query: "", Page: 2, Limit: 3}
  29. err = SearchUsers(&query)
  30. So(err, ShouldBeNil)
  31. So(len(query.Result.Users), ShouldEqual, 2)
  32. So(query.Result.TotalCount, ShouldEqual, 5)
  33. })
  34. })
  35. }