resouce_test.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package dao
  2. import (
  3. "context"
  4. "math/rand"
  5. "testing"
  6. "go-common/app/admin/main/vip/model"
  7. xsql "go-common/library/database/sql"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestDaoSelBatchCodeCount(t *testing.T) {
  11. convey.Convey("SelBatchCodeCount", t, func() {
  12. n, err := d.SelBatchCodeCount(context.TODO(), &model.ArgBatchCode{})
  13. convey.So(err, convey.ShouldBeNil)
  14. convey.So(n, convey.ShouldNotBeNil)
  15. })
  16. }
  17. func TestDaoselBatchCodeIDs(t *testing.T) {
  18. convey.Convey("selBatchCodeIDs", t, func() {
  19. ids, err := d.selBatchCodeIDs(context.TODO(), 0, 0, 0)
  20. convey.So(err, convey.ShouldBeNil)
  21. convey.So(ids, convey.ShouldNotBeNil)
  22. })
  23. }
  24. func TestDaocodeAutoArgSQL(t *testing.T) {
  25. convey.Convey("codeAutoArgSQL", t, func() {
  26. p1 := d.codeAutoArgSQL(&model.ArgCode{})
  27. convey.So(p1, convey.ShouldNotBeNil)
  28. })
  29. }
  30. func TestDaoSelCode(t *testing.T) {
  31. convey.Convey("SelCode", t, func() {
  32. _, err := d.SelCode(context.TODO(), &model.ArgCode{}, 0, 0)
  33. convey.So(err, convey.ShouldBeNil)
  34. })
  35. }
  36. func TestDaoSelBatchCodes(t *testing.T) {
  37. convey.Convey("SelBatchCodes", t, func() {
  38. _, err := d.SelBatchCodes(context.TODO(), []int64{})
  39. convey.So(err, convey.ShouldBeNil)
  40. })
  41. }
  42. func TestDaoSelBatchCode(t *testing.T) {
  43. convey.Convey("SelBatchCode", t, func() {
  44. _, err := d.SelBatchCode(context.TODO(), &model.ArgBatchCode{}, 0, 0)
  45. convey.So(err, convey.ShouldBeNil)
  46. })
  47. }
  48. func TestDaoTxAddBatchCode(t *testing.T) {
  49. var (
  50. id int64
  51. err error
  52. )
  53. convey.Convey("TxAddBatchCode", t, func() {
  54. var tx *xsql.Tx
  55. tx, err = d.BeginTran(context.Background())
  56. convey.So(err, convey.ShouldBeNil)
  57. id, err = d.TxAddBatchCode(tx, &model.BatchCode{BusinessID: 1, BatchName: "ut_test"})
  58. convey.So(err, convey.ShouldBeNil)
  59. convey.So(id, convey.ShouldNotBeNil)
  60. tx.Commit()
  61. })
  62. convey.Convey("SelCodeID", t, func() {
  63. r, err := d.SelCodeID(context.TODO(), id)
  64. convey.So(err, convey.ShouldBeNil)
  65. convey.So(r, convey.ShouldNotBeNil)
  66. })
  67. convey.Convey("SelBatchCodeID", t, func() {
  68. r, err := d.SelBatchCodeID(context.TODO(), id)
  69. convey.So(err, convey.ShouldBeNil)
  70. convey.So(r, convey.ShouldNotBeNil)
  71. })
  72. convey.Convey("SelBatchCodeName", t, func() {
  73. _, err := d.SelBatchCodeName(context.TODO(), "ut_test")
  74. convey.So(err, convey.ShouldBeNil)
  75. })
  76. convey.Convey("UpdateBatchCode", t, func() {
  77. eff, err := d.UpdateBatchCode(context.TODO(), &model.BatchCode{ID: id, BusinessID: 11})
  78. convey.So(err, convey.ShouldBeNil)
  79. convey.So(eff, convey.ShouldNotBeNil)
  80. })
  81. convey.Convey("UpdateCode", t, func() {
  82. eff, err := d.UpdateCode(context.TODO(), id, 0)
  83. convey.So(err, convey.ShouldBeNil)
  84. convey.So(eff, convey.ShouldNotBeNil)
  85. })
  86. }
  87. func TestDaoBatchAddCode(t *testing.T) {
  88. codes := []*model.ResourceCode{
  89. {BatchCodeID: int64(rand.Int31())},
  90. }
  91. convey.Convey("BatchAddCode", t, func() {
  92. tx, err := d.BeginTran(context.Background())
  93. convey.So(err, convey.ShouldBeNil)
  94. err = d.BatchAddCode(tx, codes)
  95. convey.So(err, convey.ShouldBeNil)
  96. })
  97. }