flow_test.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package archive
  2. import (
  3. "context"
  4. . "github.com/smartystreets/goconvey/convey"
  5. "testing"
  6. "go-common/app/admin/main/videoup/model/archive"
  7. )
  8. func TestDao_TxAddFlowLog(t *testing.T) {
  9. var (
  10. id int64
  11. err error
  12. )
  13. Convey("TxAddFlowLog", t, WithDao(func(d *Dao) {
  14. c := context.TODO()
  15. tx, _ := d.BeginTran(c)
  16. id, err = d.TxAddFlowLog(tx, archive.PoolPrivateOrder, archive.FlowLogAdd, 10, 421, 1, "测试添加流量日志-私单-其他")
  17. tx.Commit()
  18. So(id, ShouldBeGreaterThan, 0)
  19. So(err, ShouldBeNil)
  20. tx, _ = d.BeginTran(c)
  21. id, err = d.TxAddFlowLog(tx, archive.PoolArcForbid, archive.FlowLogAdd, 10, 421, archive.FlowGroupNoChannel, "测试添加流量日志-回查-频道禁止")
  22. tx.Commit()
  23. So(id, ShouldBeGreaterThan, 0)
  24. So(err, ShouldBeNil)
  25. }))
  26. }
  27. func TestDao_TxUpFlowState(t *testing.T) {
  28. var (
  29. id, rows int64
  30. err1, err2 error
  31. )
  32. Convey("TxUpFlowState", t, WithDao(func(d *Dao) {
  33. c := context.TODO()
  34. tx, _ := d.BeginTran(c)
  35. id, err1 = d.TxAddFlow(tx, archive.PoolArcForbid, 1, 421, archive.FlowGroupNoChannel, "测试添加频道禁止流量套餐")
  36. rows, err2 = d.TxUpFlowState(tx, id, archive.FlowOpen)
  37. tx.Commit()
  38. So(err1, ShouldBeNil)
  39. So(id, ShouldBeGreaterThan, 0)
  40. So(err2, ShouldBeNil)
  41. So(rows, ShouldEqual, 0)
  42. tx, _ = d.BeginTran(c)
  43. rows, err2 = d.TxUpFlowState(tx, id, archive.FlowDelete)
  44. tx.Commit()
  45. So(err2, ShouldBeNil)
  46. So(rows, ShouldBeGreaterThan, 0)
  47. }))
  48. }
  49. func TestDao_FlowsByOID(t *testing.T) {
  50. var (
  51. flows []*archive.FlowData
  52. err error
  53. )
  54. Convey("FlowsByOID", t, WithDao(func(d *Dao) {
  55. c := context.TODO()
  56. flows, err = d.FlowsByOID(c, 1)
  57. So(err, ShouldBeNil)
  58. }))
  59. }
  60. func TestDao_FlowUnique(t *testing.T) {
  61. var (
  62. err error
  63. )
  64. Convey("FlowUnique", t, WithDao(func(d *Dao) {
  65. c := context.TODO()
  66. _, err = d.FlowUnique(c, 1, archive.FlowGroupNoChannel, archive.PoolArcForbid)
  67. So(err, ShouldBeNil)
  68. }))
  69. }
  70. func TestDao_FlowGroupPools(t *testing.T) {
  71. Convey("FlowGroupPools", t, WithDao(func(d *Dao) {
  72. c := context.TODO()
  73. pools, err := d.FlowGroupPools(c, []int64{23, 24, 1})
  74. So(err, ShouldBeNil)
  75. So(pools, ShouldNotBeNil)
  76. t.Logf("pools(%+v)", pools)
  77. }))
  78. }
  79. func TestDao_TxUpFlow(t *testing.T) {
  80. var (
  81. c = context.Background()
  82. )
  83. Convey("TxUpFlow", t, WithDao(func(d *Dao) {
  84. tx, _ := d.BeginTran(c)
  85. _, err := d.TxUpFlow(tx, 0, 0, 0)
  86. So(err, ShouldBeNil)
  87. tx.Commit()
  88. }))
  89. }
  90. func TestDao_FindGroupIDByScope(t *testing.T) {
  91. Convey("FindGroupIDByScope", t, WithDao(func(d *Dao) {
  92. c := context.TODO()
  93. _, err := d.FindGroupIDByScope(c, 0, 0, 0, 0)
  94. So(err, ShouldBeNil)
  95. }))
  96. }
  97. func TestDao_Flows(t *testing.T) {
  98. Convey("Flows", t, WithDao(func(d *Dao) {
  99. c := context.TODO()
  100. _, err := d.Flows(c)
  101. So(err, ShouldBeNil)
  102. }))
  103. }
  104. func TestDao_FlowByPool(t *testing.T) {
  105. Convey("FlowByPool", t, WithDao(func(d *Dao) {
  106. _, err := d.FlowByPool(0, 0)
  107. So(err, ShouldBeNil)
  108. }))
  109. }