user_dao_test.go 766 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package dao
  2. import (
  3. "testing"
  4. )
  5. func TestUserDAOImpl_Save(t *testing.T) {
  6. userDAO := &UserDAOImpl{}
  7. err := InitMysql("127.0.0.1", "3306", "root", "xuan", "user")
  8. if err != nil{
  9. t.Error(err)
  10. t.FailNow()
  11. }
  12. user := &UserEntity{
  13. Username:"aoho",
  14. Password:"aoho",
  15. Email:"aoho@mail.com",
  16. }
  17. err = userDAO.Save(user)
  18. if err != nil{
  19. t.Error(err)
  20. t.FailNow()
  21. }
  22. t.Logf("new User ID is %d", user.ID)
  23. }
  24. func TestUserDAOImpl_SelectByEmail(t *testing.T) {
  25. userDAO := &UserDAOImpl{}
  26. err := InitMysql("127.0.0.1", "3306", "root", "xuan", "user")
  27. if err != nil{
  28. t.Error(err)
  29. t.FailNow()
  30. }
  31. user, err := userDAO.SelectByEmail("aoho@mail.com")
  32. if err != nil{
  33. t.Error(err)
  34. t.FailNow()
  35. }
  36. t.Logf("result uesrname is %s", user.Username)
  37. }