diff --git a/boomer.go b/boomer.go index e7b17262..37d4100e 100644 --- a/boomer.go +++ b/boomer.go @@ -47,7 +47,7 @@ func (b *Boomer) Run(testcases ...ITestCase) { } func (b *Boomer) convertBoomerTask(testcase *TestCase) *boomer.Task { - runner := NewRunner().SetDebug(b.debug) + runner := NewRunner(nil).SetDebug(b.debug) return &boomer.Task{ Name: testcase.Config.Name, Weight: testcase.Config.Weight, diff --git a/docs/cmd/hrp.md b/docs/cmd/hrp.md index 823679f5..69efd4da 100644 --- a/docs/cmd/hrp.md +++ b/docs/cmd/hrp.md @@ -22,4 +22,4 @@ Copyright 2021 debugtalk * [hrp har2case](hrp_har2case.md) - Convert HAR to json/yaml testcase files * [hrp run](hrp_run.md) - run API test -###### Auto generated by spf13/cobra on 17-Oct-2021 +###### Auto generated by spf13/cobra on 11-Nov-2021 diff --git a/docs/cmd/hrp_boom.md b/docs/cmd/hrp_boom.md index be67ff61..f2840b48 100644 --- a/docs/cmd/hrp_boom.md +++ b/docs/cmd/hrp_boom.md @@ -37,4 +37,4 @@ hrp boom [flags] * [hrp](hrp.md) - One-stop solution for HTTP(S) testing. -###### Auto generated by spf13/cobra on 17-Oct-2021 +###### Auto generated by spf13/cobra on 11-Nov-2021 diff --git a/docs/cmd/hrp_har2case.md b/docs/cmd/hrp_har2case.md index 667710f7..c9b8baea 100644 --- a/docs/cmd/hrp_har2case.md +++ b/docs/cmd/hrp_har2case.md @@ -23,4 +23,4 @@ hrp har2case harPath... [flags] * [hrp](hrp.md) - One-stop solution for HTTP(S) testing. -###### Auto generated by spf13/cobra on 17-Oct-2021 +###### Auto generated by spf13/cobra on 11-Nov-2021 diff --git a/docs/cmd/hrp_run.md b/docs/cmd/hrp_run.md index 31ffd557..f580ce58 100644 --- a/docs/cmd/hrp_run.md +++ b/docs/cmd/hrp_run.md @@ -30,4 +30,4 @@ hrp run path... [flags] * [hrp](hrp.md) - One-stop solution for HTTP(S) testing. -###### Auto generated by spf13/cobra on 17-Oct-2021 +###### Auto generated by spf13/cobra on 11-Nov-2021 diff --git a/examples/demo_test.go b/examples/demo_test.go index ab654e7b..b31cf880 100644 --- a/examples/demo_test.go +++ b/examples/demo_test.go @@ -79,7 +79,7 @@ func TestGenDemoTestCase(t *testing.T) { } func Example_TestCase() { - err := hrp.NewRunner().Run(demoTestCase) + err := hrp.NewRunner(nil).Run(demoTestCase) // hrp.Run(demoTestCase) fmt.Println(err) // Output: // @@ -87,7 +87,7 @@ func Example_TestCase() { func Example_JSONTestCase() { testCase := &hrp.TestCasePath{Path: demoTestCaseJSONPath} - err := hrp.NewRunner().Run(testCase) + err := hrp.NewRunner(nil).Run(testCase) // hrp.Run(testCase) fmt.Println(err) // Output: // @@ -95,7 +95,7 @@ func Example_JSONTestCase() { func Example_YAMTestCase() { testCase := &hrp.TestCasePath{Path: demoTestCaseYAMLPath} - err := hrp.NewRunner().Run(testCase) + err := hrp.NewRunner(nil).Run(testCase) // hrp.Run(testCase) fmt.Println(err) // Output: // diff --git a/examples/extract_test.go b/examples/extract_test.go index 67e8a654..7f3891bf 100644 --- a/examples/extract_test.go +++ b/examples/extract_test.go @@ -37,7 +37,7 @@ func TestCaseExtractStepSingle(t *testing.T) { }, } - err := hrp.Run(t, testcase) + err := hrp.NewRunner(t).Run(testcase) if err != nil { t.Fatalf("run testcase error: %v", err) } @@ -82,7 +82,7 @@ func TestCaseExtractStepAssociation(t *testing.T) { }, } - err := hrp.Run(t, testcase) + err := hrp.NewRunner(t).Run(testcase) if err != nil { t.Fatalf("run testcase error: %v", err) } diff --git a/examples/function_test.go b/examples/function_test.go index 768224af..2ae4d642 100644 --- a/examples/function_test.go +++ b/examples/function_test.go @@ -40,7 +40,7 @@ func TestCaseCallFunction(t *testing.T) { }, } - err := hrp.Run(t, testcase) + err := hrp.NewRunner(t).Run(testcase) if err != nil { t.Fatalf("run testcase error: %v", err) } diff --git a/examples/request_test.go b/examples/request_test.go index c0d41b55..a17047a5 100644 --- a/examples/request_test.go +++ b/examples/request_test.go @@ -70,7 +70,7 @@ func TestCaseBasicRequest(t *testing.T) { }, } - err := hrp.Run(t, testcase) + err := hrp.NewRunner(t).Run(testcase) if err != nil { t.Fatalf("run testcase error: %v", err) } diff --git a/examples/validate_test.go b/examples/validate_test.go index 42cf508f..17f768ca 100644 --- a/examples/validate_test.go +++ b/examples/validate_test.go @@ -51,7 +51,7 @@ func TestCaseValidateStep(t *testing.T) { }, } - err := hrp.Run(t, testcase) + err := hrp.NewRunner(t).Run(testcase) if err != nil { t.Fatalf("run testcase error: %v", err) } diff --git a/examples/variables_test.go b/examples/variables_test.go index edf22cf2..2d4f4c55 100644 --- a/examples/variables_test.go +++ b/examples/variables_test.go @@ -33,7 +33,7 @@ func TestCaseConfigVariables(t *testing.T) { }, } - err := hrp.Run(t, testcase) + err := hrp.NewRunner(t).Run(testcase) if err != nil { t.Fatalf("run testcase error: %v", err) } @@ -66,7 +66,7 @@ func TestCaseStepVariables(t *testing.T) { }, } - err := hrp.Run(t, testcase) + err := hrp.NewRunner(t).Run(testcase) if err != nil { t.Fatalf("run testcase error: %v", err) } @@ -104,7 +104,7 @@ func TestCaseOverrideConfigVariables(t *testing.T) { }, } - err := hrp.Run(t, testcase) + err := hrp.NewRunner(t).Run(testcase) if err != nil { t.Fatalf("run testcase error: %v", err) } @@ -151,7 +151,7 @@ func TestCaseParseVariables(t *testing.T) { }, } - err := hrp.Run(t, testcase) + err := hrp.NewRunner(t).Run(testcase) if err != nil { t.Fatalf("run testcase error: %v", err) } diff --git a/hrp/cmd/run.go b/hrp/cmd/run.go index 782cff8c..6cf20870 100644 --- a/hrp/cmd/run.go +++ b/hrp/cmd/run.go @@ -20,7 +20,7 @@ var runCmd = &cobra.Command{ for _, arg := range args { paths = append(paths, &hrp.TestCasePath{Path: arg}) } - runner := hrp.NewRunner().SetDebug(!silentFlag) + runner := hrp.NewRunner(nil).SetDebug(!silentFlag) if proxyUrl != "" { runner.SetProxyUrl(proxyUrl) } diff --git a/runner.go b/runner.go index c56d0b8c..8acc56af 100644 --- a/runner.go +++ b/runner.go @@ -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 diff --git a/runner_test.go b/runner_test.go index 3328a436..72476dde 100644 --- a/runner_test.go +++ b/runner_test.go @@ -32,7 +32,7 @@ func TestHttpRunner(t *testing.T) { } testcase3 := &TestCasePath{demoTestCaseJSONPath} - err := Run(t, testcase1, testcase2, testcase3) + err := NewRunner(t).Run(testcase1, testcase2, testcase3) if err != nil { t.Fatalf("run testcase error: %v", err) } diff --git a/step_test.go b/step_test.go index a41d3cb8..1f2e56e1 100644 --- a/step_test.go +++ b/step_test.go @@ -77,7 +77,7 @@ func TestRunRequestRun(t *testing.T) { config := &TConfig{ BaseURL: "https://postman-echo.com", } - runner := NewRunner().SetDebug(true).WithTestingT(t) + runner := NewRunner(t).SetDebug(true) if _, err := runner.runStep(stepGET, config); err != nil { t.Fatalf("tStep.Run() error: %s", err) }