| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 | 
							- package service
 
- import (
 
- 	"context"
 
- 	"github.com/longjoy/micro-go-course/section11/user/dao"
 
- 	"github.com/longjoy/micro-go-course/section11/user/redis"
 
- 	"testing"
 
- )
 
- func TestUserServiceImpl_Login(t *testing.T) {
 
- 	err := dao.InitMysql("127.0.0.1", "3306", "root", "123456", "user")
 
- 	if err != nil{
 
- 		t.Error(err)
 
- 		t.FailNow()
 
- 	}
 
- 	err = redis.InitRedis("127.0.0.1","6379", "" )
 
- 	if err != nil{
 
- 		t.Error(err)
 
- 		t.FailNow()
 
- 	}
 
- 	userService := &UserServiceImpl{
 
- 		userDAO: &dao.UserDAOImpl{},
 
- 	}
 
- 	user, err := userService.Login(context.Background(), "aoho@mail.com", "aoho")
 
- 	if err != nil{
 
- 		t.Error(err)
 
- 		t.FailNow()
 
- 	}
 
- 	t.Logf("user id is %d", user.ID)
 
- }
 
- func TestUserServiceImpl_Register(t *testing.T) {
 
- 	err := dao.InitMysql("127.0.0.1", "3306", "root", "123456", "user")
 
- 	if err != nil{
 
- 		t.Error(err)
 
- 		t.FailNow()
 
- 	}
 
- 	err = redis.InitRedis("127.0.0.1","6379", "" )
 
- 	if err != nil{
 
- 		t.Error(err)
 
- 		t.FailNow()
 
- 	}
 
- 	userService := &UserServiceImpl{
 
- 		userDAO: &dao.UserDAOImpl{},
 
- 	}
 
- 	user, err := userService.Register(context.Background(),
 
- 		&RegisterUserVO{
 
- 			Username:"aoho",
 
- 			Password:"aoho",
 
- 			Email:"aoho@mail.com",
 
- 		})
 
- 	if err != nil{
 
- 		t.Error(err)
 
- 		t.FailNow()
 
- 	}
 
- 	t.Logf("user id is %d", user.ID)
 
- }
 
 
  |