d56b9bea0519dcf735d102ec863f039d3930ed52.svn-base 769 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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", "123456", "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", "123456", "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. }