dao_test.go 658 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package dao
  2. import (
  3. "context"
  4. "flag"
  5. "path/filepath"
  6. "strings"
  7. "go-common/app/admin/ep/merlin/conf"
  8. _ "github.com/go-sql-driver/mysql"
  9. "gopkg.in/h2non/gock.v1"
  10. )
  11. var (
  12. d *Dao
  13. c context.Context
  14. )
  15. func init() {
  16. dir, _ := filepath.Abs("../cmd/convey-test.toml")
  17. flag.Set("conf", dir)
  18. conf.Init()
  19. d = New(conf.Conf)
  20. d.httpClient.SetTransport(gock.DefaultTransport)
  21. c = ctx()
  22. }
  23. func httpMock(method, url string) *gock.Request {
  24. r := gock.New(url)
  25. r.Method = strings.ToUpper(method)
  26. return r
  27. }
  28. func ctx() context.Context {
  29. return context.Background()
  30. }
  31. func WithPaasToken(f func()) func() {
  32. return func() {
  33. d.paasToken(c)
  34. f()
  35. }
  36. }