b2798216b5785e086d9805a28beee10bd5441b0b.svn-base 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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", "root", "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", "root", "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. }
  38. func TestUserDAOImpl_SelectPass(t *testing.T) {
  39. userDAO := &UserDAOImpl{}
  40. err := InitMysql("127.0.0.1", "3306", "root", "root", "user")
  41. if err != nil{
  42. t.Error(err)
  43. t.FailNow()
  44. }
  45. user, err := userDAO.SelectPassByUserNameV3("aoho")
  46. if err != nil{
  47. t.Error(err)
  48. t.FailNow()
  49. }
  50. t.Logf("result uesrname is %v", *user)
  51. }