user_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/admin/main/tv/model"
  6. "go-common/library/log"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestDaoGetByMId(t *testing.T) {
  10. d.saveUser()
  11. convey.Convey("GetByMId", t, func(ctx convey.C) {
  12. var (
  13. c = context.Background()
  14. mid = int64(100000000)
  15. )
  16. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  17. userInfo, err := d.GetByMId(c, mid)
  18. ctx.Convey("Then err should be nil.userInfo should not be nil.", func(ctx convey.C) {
  19. ctx.So(err, convey.ShouldBeNil)
  20. ctx.So(userInfo, convey.ShouldNotBeNil)
  21. })
  22. })
  23. })
  24. d.delUser()
  25. }
  26. func (d *Dao) saveUser() {
  27. userInfo := &model.TvUserInfo{
  28. MID: 100000000,
  29. RecentPayTime: 1544613229,
  30. }
  31. if err := d.DB.Save(userInfo).Error; err != nil {
  32. log.Error("SaveUser error(%v)", err)
  33. }
  34. }
  35. func (d *Dao) delUser() {
  36. userInfo := &model.TvUserInfo{
  37. MID: 100000000,
  38. }
  39. if err := d.DB.Where("mid = ?", userInfo.MID).Delete(userInfo).Error; err != nil {
  40. log.Error("DelUser error(%v)", err)
  41. }
  42. }