mysql_article_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. . "github.com/smartystreets/goconvey/convey"
  6. )
  7. var (
  8. dataID = int64(175)
  9. noDataID = int64(100000000)
  10. )
  11. func Test_ArticleContent(t *testing.T) {
  12. Convey("get data", t, WithMysql(func(d *Dao) {
  13. res, err := d.ArticleContent(context.TODO(), dataID)
  14. So(err, ShouldBeNil)
  15. So(res, ShouldNotBeEmpty)
  16. }))
  17. Convey("no data", t, WithDao(func(d *Dao) {
  18. res, err := d.ArticleContent(context.TODO(), noDataID)
  19. So(err, ShouldBeNil)
  20. So(res, ShouldBeEmpty)
  21. }))
  22. }
  23. func Test_ArticleMeta(t *testing.T) {
  24. Convey("get data", t, WithMysql(func(d *Dao) {
  25. res, err := d.ArticleMeta(context.TODO(), dataID)
  26. So(err, ShouldBeNil)
  27. So(res, ShouldNotBeNil)
  28. So(res.PublishTime, ShouldNotEqual, 0)
  29. }))
  30. Convey("no data", t, WithDao(func(d *Dao) {
  31. res, err := d.ArticleMeta(context.TODO(), noDataID)
  32. So(err, ShouldBeNil)
  33. So(res, ShouldBeNil)
  34. }))
  35. }
  36. func Test_ArticleMetas(t *testing.T) {
  37. Convey("get data", t, WithMysql(func(d *Dao) {
  38. res, err := d.ArticleMetas(context.TODO(), []int64{dataID})
  39. So(err, ShouldBeNil)
  40. So(res, ShouldNotBeEmpty)
  41. }))
  42. Convey("no data", t, WithDao(func(d *Dao) {
  43. res, err := d.ArticleMetas(context.TODO(), []int64{noDataID})
  44. So(err, ShouldBeNil)
  45. So(res, ShouldBeEmpty)
  46. }))
  47. }
  48. func Test_UpperArticleCount(t *testing.T) {
  49. Convey("get data", t, WithMysql(func(d *Dao) {
  50. res, err := d.UpperArticleCount(context.TODO(), dataID)
  51. So(err, ShouldBeNil)
  52. So(res, ShouldBeGreaterThan, 0)
  53. }))
  54. Convey("no data", t, WithDao(func(d *Dao) {
  55. res, err := d.UpperArticleCount(context.TODO(), _noData)
  56. So(err, ShouldBeNil)
  57. So(res, ShouldEqual, 0)
  58. }))
  59. }