dao_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package dao
  2. import (
  3. "context"
  4. "flag"
  5. "testing"
  6. "go-common/app/job/main/block/conf"
  7. "go-common/app/job/main/block/model"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. var (
  11. dao *Dao
  12. ctx = context.TODO()
  13. )
  14. func TestMain(m *testing.M) {
  15. flag.Set("conf", "../cmd/block-service-test.toml")
  16. var err error
  17. if err = conf.Init(); err != nil {
  18. panic(err)
  19. }
  20. dao = New()
  21. defer dao.Close()
  22. m.Run()
  23. }
  24. func TestDB(t *testing.T) {
  25. Convey("db", t, func() {
  26. tx, err := dao.BeginTX(ctx)
  27. So(err, ShouldBeNil)
  28. var (
  29. mid int64 = 46333
  30. )
  31. err = dao.UpsertAddBlockCount(ctx, mid)
  32. So(err, ShouldBeNil)
  33. err = dao.TxUpsertUser(ctx, tx, mid, model.BlockStatusFalse)
  34. So(err, ShouldBeNil)
  35. var (
  36. history = &model.DBHistory{
  37. MID: mid,
  38. Source: model.BlockSourceRemove,
  39. Comment: "ut test",
  40. Action: model.BlockActionAdminRemove,
  41. }
  42. )
  43. err = dao.TxInsertHistory(ctx, tx, history)
  44. So(err, ShouldBeNil)
  45. err = tx.Rollback()
  46. So(err, ShouldBeNil)
  47. })
  48. }
  49. func TestTool(t *testing.T) {
  50. Convey("tool", t, func() {
  51. var (
  52. mids = []int64{1, 2, 3, 46333, 35858}
  53. )
  54. str := midsToParam(mids)
  55. So(str, ShouldEqual, "1,2,3,46333,35858")
  56. })
  57. }