mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-06 16:07:45 +08:00
feat: set proxy url
This commit is contained in:
+11
-9
@@ -29,15 +29,17 @@ var boomCmd = &cobra.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var masterHost string
|
var (
|
||||||
var masterPort int
|
masterHost string
|
||||||
var maxRPS int64 // TODO: init boomer with this flag
|
masterPort int
|
||||||
var requestIncreaseRate string // TODO: init boomer with this flag
|
maxRPS int64 // TODO: init boomer with this flag
|
||||||
var runTasks string // TODO: init boomer with this flag
|
requestIncreaseRate string // TODO: init boomer with this flag
|
||||||
var memoryProfile string
|
runTasks string // TODO: init boomer with this flag
|
||||||
var memoryProfileDuration time.Duration
|
memoryProfile string
|
||||||
var cpuProfile string
|
memoryProfileDuration time.Duration
|
||||||
var cpuProfileDuration time.Duration
|
cpuProfile string
|
||||||
|
cpuProfileDuration time.Duration
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RootCmd.AddCommand(boomCmd)
|
RootCmd.AddCommand(boomCmd)
|
||||||
|
|||||||
+12
-11
@@ -1,8 +1,6 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/httprunner/httpboomer"
|
"github.com/httprunner/httpboomer"
|
||||||
@@ -18,23 +16,26 @@ var runCmd = &cobra.Command{
|
|||||||
$ httpboomer run examples/ # run testcases in specified folder`,
|
$ httpboomer run examples/ # run testcases in specified folder`,
|
||||||
Args: cobra.MinimumNArgs(1),
|
Args: cobra.MinimumNArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
// --silent flag
|
|
||||||
silentFlag, err := cmd.Flags().GetBool("silent")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
log.Printf("[runCmd] set --silent flag: %v", silentFlag)
|
|
||||||
|
|
||||||
var paths []httpboomer.ITestCase
|
var paths []httpboomer.ITestCase
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
paths = append(paths, &httpboomer.TestCasePath{Path: arg})
|
paths = append(paths, &httpboomer.TestCasePath{Path: arg})
|
||||||
}
|
}
|
||||||
return httpboomer.NewRunner().SetDebug(!silentFlag).Run(paths...)
|
runner := httpboomer.NewRunner().SetDebug(!silentFlag)
|
||||||
|
if proxyUrl != "" {
|
||||||
|
runner.SetProxyUrl(proxyUrl)
|
||||||
|
}
|
||||||
|
return runner.Run(paths...)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
silentFlag bool
|
||||||
|
proxyUrl string
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RootCmd.AddCommand(runCmd)
|
RootCmd.AddCommand(runCmd)
|
||||||
runCmd.Flags().BoolP("silent", "s", false, "Disable logging request & response details")
|
runCmd.Flags().BoolVarP(&silentFlag, "silent", "s", false, "disable logging request & response details")
|
||||||
|
runCmd.Flags().StringVarP(&proxyUrl, "proxy-url", "p", "", "set proxy url")
|
||||||
// runCmd.Flags().BoolP("gen-html-report", "r", false, "Generate HTML report")
|
// runCmd.Flags().BoolP("gen-html-report", "r", false, "Generate HTML report")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,15 +28,23 @@ type Runner struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) WithTestingT(t *testing.T) *Runner {
|
func (r *Runner) WithTestingT(t *testing.T) *Runner {
|
||||||
|
log.Printf("[init] WithTestingT: %v", t)
|
||||||
r.t = t
|
r.t = t
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) SetDebug(debug bool) *Runner {
|
func (r *Runner) SetDebug(debug bool) *Runner {
|
||||||
|
log.Printf("[init] SetDebug: %v", debug)
|
||||||
r.debug = debug
|
r.debug = debug
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Runner) SetProxyUrl(proxyUrl string) *Runner {
|
||||||
|
log.Printf("[init] SetProxyUrl: %s", proxyUrl)
|
||||||
|
r.client.SetProxyUrl(proxyUrl)
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Runner) Run(testcases ...ITestCase) error {
|
func (r *Runner) Run(testcases ...ITestCase) error {
|
||||||
for _, iTestCase := range testcases {
|
for _, iTestCase := range testcases {
|
||||||
testcase, err := iTestCase.ToTestCase()
|
testcase, err := iTestCase.ToTestCase()
|
||||||
@@ -156,7 +164,6 @@ func (r *Runner) runStepRequest(step *TStep) (stepData *StepData, err error) {
|
|||||||
|
|
||||||
// do request action
|
// do request action
|
||||||
req.Debug = r.debug
|
req.Debug = r.debug
|
||||||
// r.client.SetProxyUrl("http://127.0.0.1:8888")
|
|
||||||
resp, err := r.client.Do(string(step.Request.Method), step.Request.URL, v...)
|
resp, err := r.client.Do(string(step.Request.Method), step.Request.URL, v...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user