mysql_user_test.go 861 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package dao
  2. import (
  3. "testing"
  4. "time"
  5. "go-common/app/admin/ep/merlin/model"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. var (
  9. testTime = time.Now().Format("2006_01_02_15_04_05")
  10. testUser = model.User{
  11. Name: testTime,
  12. EMail: testTime + "@bilibili.com"}
  13. )
  14. func Test_User(t *testing.T) {
  15. Convey("test CreateUser", t, func() {
  16. err := d.CreateUser(&testUser)
  17. So(err, ShouldBeNil)
  18. })
  19. Convey("find user by user name", t, func() {
  20. userInDb, err := d.FindUserByUserName(testUser.Name)
  21. So(userInDb.EMail, ShouldEqual, testUser.EMail)
  22. So(err, ShouldBeNil)
  23. })
  24. Convey("find user by id", t, func() {
  25. userID := testUser.ID
  26. userInDb, err := d.FindUserByID(userID)
  27. So(userInDb.EMail, ShouldEqual, testUser.EMail)
  28. So(err, ShouldBeNil)
  29. })
  30. Convey("delete user", t, func() {
  31. err := d.DelUser(&testUser)
  32. So(err, ShouldBeNil)
  33. })
  34. }