mysql_test.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/job/main/passport-game-cloud/model"
  6. "github.com/go-sql-driver/mysql"
  7. "github.com/pkg/errors"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestDao_PingMySQL(t *testing.T) {
  11. once.Do(startDao)
  12. if err := d.cloudDB.Ping(context.TODO()); err != nil {
  13. t.Errorf("dao.cloudDB.Ping() error(%v)", err)
  14. t.FailNow()
  15. }
  16. }
  17. func TestDao_AddMemberInfo(t *testing.T) {
  18. once.Do(startDao)
  19. info := &model.Info{
  20. Mid: 110000130,
  21. Face: "/bfs/face/bbc031c4b7bdabb6635a246ce7386ccb587c5214811111.jpg",
  22. }
  23. if a, err := d.AddMemberInfo(context.TODO(), info); err != nil {
  24. t.FailNow()
  25. } else {
  26. t.Logf("a: %d", a)
  27. }
  28. }
  29. func TestDao_UpdateAsoAccount(t *testing.T) {
  30. once.Do(startDao)
  31. Convey("update a aso account", t, func() {
  32. account := &model.AsoAccount{
  33. Mid: 12047569,
  34. UserID: "bili_1710676855",
  35. Uname: "Bili_12047569",
  36. Pwd: "3686c9d96ae6896fe117319ba6c07087",
  37. Salt: "pdMXF856",
  38. Email: "62fe0d616162f56ecab3e12a2de83ea6",
  39. Tel: "bdb27b0300e3984e48e7aea5c672a243",
  40. CountryID: 1,
  41. MobileVerified: 1,
  42. Isleak: 0,
  43. }
  44. affected, err := d.UpdateAsoAccount(context.TODO(), account)
  45. So(err, ShouldBeNil)
  46. So(affected, ShouldEqual, 1)
  47. })
  48. }
  49. func TestDao_AddAsoAccount(t *testing.T) {
  50. once.Do(startDao)
  51. account := &model.AsoAccount{
  52. Mid: 12047569,
  53. UserID: "bili_1710676855",
  54. Uname: "Bili_12047569",
  55. Pwd: "3686c9d96ae6896fe117319ba6c07087",
  56. Salt: "pdMXF856",
  57. Email: "62fe0d616162f56ecab3e12a2de83ea6",
  58. Tel: "bdb27b0300e3984e48e7aea5c672a243",
  59. CountryID: 1,
  60. MobileVerified: 1,
  61. Isleak: 0,
  62. }
  63. if _, err := d.AddAsoAccount(context.TODO(), account); err != nil {
  64. switch nErr := errors.Cause(err).(type) {
  65. case *mysql.MySQLError:
  66. if nErr.Number != 1062 {
  67. t.Errorf("expected MySQL error 1062 but got error(%v)", err)
  68. t.FailNow()
  69. }
  70. }
  71. } else {
  72. t.FailNow()
  73. }
  74. }