refactor: runner api

This commit is contained in:
debugtalk
2021-11-11 16:23:30 +08:00
parent c16fad8905
commit 00284ff610
15 changed files with 28 additions and 30 deletions

View File

@@ -18,13 +18,17 @@ import (
)
// run API test with default configs
func Run(t *testing.T, testcases ...ITestCase) error {
return NewRunner().WithTestingT(t).SetDebug(true).Run(testcases...)
func Run(testcases ...ITestCase) error {
t := &testing.T{}
return NewRunner(t).SetDebug(true).Run(testcases...)
}
func NewRunner() *Runner {
func NewRunner(t *testing.T) *Runner {
if t == nil {
t = &testing.T{}
}
return &Runner{
t: &testing.T{},
t: t,
debug: false, // default to turn off debug
client: &http.Client{
Transport: &http.Transport{
@@ -41,12 +45,6 @@ type Runner struct {
client *http.Client
}
func (r *Runner) WithTestingT(t *testing.T) *Runner {
log.Info().Msg("[init] WithTestingT")
r.t = t
return r
}
func (r *Runner) SetDebug(debug bool) *Runner {
log.Info().Bool("debug", debug).Msg("[init] SetDebug")
r.debug = debug