mysql_user_test.go 860 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package dao
  2. import (
  3. "testing"
  4. "time"
  5. . "github.com/smartystreets/goconvey/convey"
  6. "go-common/app/admin/ep/marthe/model"
  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. }