user_test.go 938 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package service
  2. import (
  3. "context"
  4. "reflect"
  5. "testing"
  6. "go-common/app/admin/main/apm/dao"
  7. "github.com/bouk/monkey"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestUser(t *testing.T) {
  11. convey.Convey("user", t, func() {
  12. t.Log("user test")
  13. })
  14. }
  15. func TestServiceGetUser(t *testing.T) {
  16. convey.Convey("GetUser", t, func(ctx convey.C) {
  17. var (
  18. c = context.Background()
  19. username = "chenjianrong"
  20. )
  21. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  22. guard := monkey.PatchInstanceMethod(reflect.TypeOf(svr.dao), "GitLabFace", func(_ *dao.Dao, _ context.Context, _ string) (string, error) {
  23. return "http://git.bilibili.co/some/pic.jpg", nil
  24. })
  25. defer guard.Unpatch()
  26. usr, err := svr.GetUser(c, username)
  27. ctx.Convey("Then err should be nil.usr should not be nil.", func(ctx convey.C) {
  28. ctx.So(err, convey.ShouldBeNil)
  29. ctx.So(usr, convey.ShouldNotBeNil)
  30. })
  31. })
  32. })
  33. }