business_test.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "testing"
  6. "go-common/app/admin/main/reply/model"
  7. . "github.com/smartystreets/goconvey/convey"
  8. )
  9. func delBusiness(d *Dao, id int64) error {
  10. _delBsSQL := "Delete from business where id = %d"
  11. _, err := d.db.Exec(context.Background(), fmt.Sprintf(_delBsSQL, id))
  12. if err != nil {
  13. return err
  14. }
  15. return nil
  16. }
  17. func TestBusiness(t *testing.T) {
  18. var (
  19. id1 int64
  20. id2 int64
  21. err error
  22. bs1 = model.Business{
  23. Type: 244,
  24. Name: "TestName",
  25. Appkey: "TestAppKey",
  26. Remark: "TestRemark",
  27. Alias: "TestAlias",
  28. }
  29. bs2 = model.Business{
  30. Type: 245,
  31. Name: "TestName",
  32. Appkey: "TestAppKey",
  33. Remark: "TestRemark",
  34. Alias: "TestAlias2",
  35. }
  36. b []*model.Business
  37. bu *model.Business
  38. )
  39. c := context.Background()
  40. Convey("test dao business", t, WithDao(func(d *Dao) {
  41. id1, err = d.InBusiness(c, bs1.Type, bs1.Name, bs1.Appkey, bs1.Remark, bs1.Alias)
  42. So(err, ShouldBeNil)
  43. So(id1, ShouldBeGreaterThan, 0)
  44. defer delBusiness(d, id1)
  45. id2, err = d.InBusiness(c, bs2.Type, bs2.Name, bs2.Appkey, bs2.Remark, bs2.Alias)
  46. So(err, ShouldBeNil)
  47. So(id2, ShouldBeGreaterThan, 0)
  48. defer delBusiness(d, id2)
  49. Convey("list business", WithDao(func(d *Dao) {
  50. b, err = d.ListBusiness(c, 0)
  51. So(err, ShouldBeNil)
  52. So(len(b), ShouldBeGreaterThan, 0)
  53. }))
  54. Convey("update business", WithDao(func(d *Dao) {
  55. bu, err = d.Business(c, 245)
  56. So(err, ShouldBeNil)
  57. So(bu.Name, ShouldEqual, "TestName")
  58. _, err = d.UpBusiness(c, "TestChangeName", bu.Appkey, bu.Remark, bu.Alias, bu.Type)
  59. So(err, ShouldBeNil)
  60. bu, err = d.Business(c, 245)
  61. So(err, ShouldBeNil)
  62. So(bu.Name, ShouldEqual, "TestChangeName")
  63. }))
  64. Convey("update business state", WithDao(func(d *Dao) {
  65. _, err = d.UpBusinessState(c, 1, bu.Type)
  66. So(err, ShouldBeNil)
  67. bu, err = d.Business(c, 245)
  68. So(err, ShouldBeNil)
  69. So(bu.Type, ShouldEqual, 245)
  70. }))
  71. }))
  72. }