96faf1402bb0b32cfef2813a48a94496209f18bc.svn-base 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package service
  2. import (
  3. "context"
  4. "github.com/longjoy/micro-go-course/section11/user/dao"
  5. "github.com/longjoy/micro-go-course/section11/user/redis"
  6. "testing"
  7. )
  8. func TestUserServiceImpl_Login(t *testing.T) {
  9. err := dao.InitMysql("127.0.0.1", "3306", "root", "123456", "user")
  10. if err != nil{
  11. t.Error(err)
  12. t.FailNow()
  13. }
  14. err = redis.InitRedis("127.0.0.1","6379", "" )
  15. if err != nil{
  16. t.Error(err)
  17. t.FailNow()
  18. }
  19. userService := &UserServiceImpl{
  20. userDAO: &dao.UserDAOImpl{},
  21. }
  22. user, err := userService.Login(context.Background(), "aoho@mail.com", "aoho")
  23. if err != nil{
  24. t.Error(err)
  25. t.FailNow()
  26. }
  27. t.Logf("user id is %d", user.ID)
  28. }
  29. func TestUserServiceImpl_Register(t *testing.T) {
  30. err := dao.InitMysql("127.0.0.1", "3306", "root", "123456", "user")
  31. if err != nil{
  32. t.Error(err)
  33. t.FailNow()
  34. }
  35. err = redis.InitRedis("127.0.0.1","6379", "" )
  36. if err != nil{
  37. t.Error(err)
  38. t.FailNow()
  39. }
  40. userService := &UserServiceImpl{
  41. userDAO: &dao.UserDAOImpl{},
  42. }
  43. user, err := userService.Register(context.Background(),
  44. &RegisterUserVO{
  45. Username:"aoho",
  46. Password:"aoho",
  47. Email:"aoho@mail.com",
  48. })
  49. if err != nil{
  50. t.Error(err)
  51. t.FailNow()
  52. }
  53. t.Logf("user id is %d", user.ID)
  54. }