sqlstore_test.go 880 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package sqlstore
  2. import (
  3. "testing"
  4. "github.com/go-xorm/xorm"
  5. . "github.com/smartystreets/goconvey/convey"
  6. m "github.com/torkelo/grafana-pro/pkg/models"
  7. )
  8. func InitTestDB(t *testing.T) {
  9. x, err := xorm.NewEngine("sqlite3", ":memory:")
  10. if err != nil {
  11. t.Fatalf("Failed to init in memory sqllite3 db %v", err)
  12. }
  13. SetEngine(x, false)
  14. }
  15. type Test struct {
  16. Id int64
  17. Name string
  18. }
  19. func TestDataAccess(t *testing.T) {
  20. Convey("Testing DB", t, func() {
  21. InitTestDB(t)
  22. Convey("Can add datasource", func() {
  23. err := AddDataSource(&m.AddDataSourceCommand{
  24. AccountId: 10,
  25. Type: m.DS_GRAPHITE,
  26. Access: m.DS_ACCESS_DIRECT,
  27. Url: "http://test",
  28. })
  29. So(err, ShouldBeNil)
  30. query := m.GetDataSourcesQuery{AccountId: 10}
  31. err = GetDataSources(&query)
  32. So(err, ShouldBeNil)
  33. So(len(query.Resp), ShouldEqual, 1)
  34. })
  35. })
  36. }