av_breach_test.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package income
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestIncomeBreachCount(t *testing.T) {
  8. convey.Convey("BreachCount", t, func(ctx convey.C) {
  9. var (
  10. c = context.Background()
  11. query = "id > 0"
  12. )
  13. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  14. total, err := d.BreachCount(c, query)
  15. ctx.Convey("Then err should be nil.total should not be nil.", func(ctx convey.C) {
  16. ctx.So(err, convey.ShouldBeNil)
  17. ctx.So(total, convey.ShouldNotBeNil)
  18. })
  19. })
  20. })
  21. }
  22. func TestIncomeListArchiveBreach(t *testing.T) {
  23. convey.Convey("ListArchiveBreach", t, func(ctx convey.C) {
  24. var (
  25. c = context.Background()
  26. query = "id > 0"
  27. )
  28. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  29. breachs, err := d.ListArchiveBreach(c, query)
  30. ctx.Convey("Then err should be nil.breachs should not be nil.", func(ctx convey.C) {
  31. ctx.So(err, convey.ShouldBeNil)
  32. ctx.So(breachs, convey.ShouldNotBeNil)
  33. })
  34. })
  35. })
  36. }
  37. func TestIncomeTxInsertAvBreach(t *testing.T) {
  38. convey.Convey("TxInsertAvBreach", t, func(ctx convey.C) {
  39. var (
  40. tx, _ = d.BeginTran(context.Background())
  41. val = "(520,1100,'2018-01-01',10,0,'aa','2018-01-01')"
  42. )
  43. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  44. defer tx.Commit()
  45. Exec(context.Background(), "DELETE FROM av_breach_record WHERE av_id = 520")
  46. rows, err := d.TxInsertAvBreach(tx, val)
  47. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  48. ctx.So(err, convey.ShouldBeNil)
  49. ctx.So(rows, convey.ShouldNotBeNil)
  50. })
  51. })
  52. })
  53. }
  54. func TestIncomeGetAvBreachByMIDs(t *testing.T) {
  55. convey.Convey("GetAvBreachByMIDs", t, func(ctx convey.C) {
  56. var (
  57. c = context.Background()
  58. mids = []int64{1000}
  59. types = []int64{1}
  60. )
  61. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  62. Exec(c, "INSERT INTO av_breach_record(mid, ctype) VALUES(1000, 1)")
  63. breachs, err := d.GetAvBreachByMIDs(c, mids, types)
  64. ctx.Convey("Then err should be nil.breachs should not be nil.", func(ctx convey.C) {
  65. ctx.So(err, convey.ShouldBeNil)
  66. ctx.So(breachs, convey.ShouldNotBeNil)
  67. })
  68. })
  69. })
  70. }
  71. func TestIncomeTxUpdateBreachPre(t *testing.T) {
  72. convey.Convey("TxUpdateBreachPre", t, func(ctx convey.C) {
  73. var (
  74. tx, _ = d.BeginTran(context.Background())
  75. aids = []int64{1001}
  76. cdate = "2018-06-01"
  77. )
  78. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  79. defer tx.Commit()
  80. rows, err := d.TxUpdateBreachPre(tx, aids, cdate)
  81. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  82. ctx.So(err, convey.ShouldBeNil)
  83. ctx.So(rows, convey.ShouldNotBeNil)
  84. })
  85. })
  86. })
  87. }