blacklist_test.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestDaoListBlacklist(t *testing.T) {
  8. convey.Convey("ListBlacklist", t, func(ctx convey.C) {
  9. var (
  10. query = "id > 0"
  11. from = int(0)
  12. limit = int(0)
  13. sort = "-id"
  14. )
  15. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  16. Exec(context.Background(), "INSERT INTO av_black_list(av_id, mid, ctype) VALUES(1993, 1001, 0)")
  17. list, total, err := d.ListBlacklist(query, from, limit, sort)
  18. ctx.Convey("Then err should be nil.list,total should not be nil.", func(ctx convey.C) {
  19. ctx.So(err, convey.ShouldBeNil)
  20. ctx.So(total, convey.ShouldNotBeNil)
  21. ctx.So(list, convey.ShouldNotBeNil)
  22. })
  23. })
  24. })
  25. }
  26. func TestDaoGetAvIncomeStatis(t *testing.T) {
  27. convey.Convey("GetAvIncomeStatis", t, func(ctx convey.C) {
  28. var (
  29. query = "id > 0"
  30. )
  31. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  32. Exec(context.Background(), "INSERT INTO av_income_statis(av_id, total_income) VALUE(1000, 100)")
  33. avIncome, err := d.GetAvIncomeStatis(query)
  34. ctx.Convey("Then err should be nil.avIncome should not be nil.", func(ctx convey.C) {
  35. ctx.So(err, convey.ShouldBeNil)
  36. ctx.So(avIncome, convey.ShouldNotBeNil)
  37. })
  38. })
  39. })
  40. }
  41. func TestDaoUpdateBlacklist(t *testing.T) {
  42. convey.Convey("UpdateBlacklist", t, func(ctx convey.C) {
  43. var (
  44. avID = int64(1993)
  45. ctype = int(0)
  46. update = make(map[string]interface{})
  47. )
  48. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  49. Exec(context.Background(), "DELETE FROM av_black_list WHERE av_id = 1993")
  50. Exec(context.Background(), "INSERT INTO av_black_list(av_id, mid, ctype) VALUES(1993, 1001, 0) ON DUPLICATE KEY UPDATE ctype = 0")
  51. update["ctype"] = 1
  52. err := d.UpdateBlacklist(avID, ctype, update)
  53. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  54. ctx.So(err, convey.ShouldBeNil)
  55. })
  56. })
  57. })
  58. }