user_service_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package service
  2. import (
  3. "context"
  4. "github.com/longjoy/micro-go-course/section10/user/dao"
  5. "github.com/longjoy/micro-go-course/section10/user/redis"
  6. "testing"
  7. )
  8. func TestUserServiceImpl_Login(t *testing.T) {
  9. err := dao.InitMysql("127.0.0.1", "3306", "root", "xuan", "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", "xuan", "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. }