mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
feat: set proxy url
This commit is contained in:
@@ -29,15 +29,17 @@ var boomCmd = &cobra.Command{
|
||||
},
|
||||
}
|
||||
|
||||
var masterHost string
|
||||
var masterPort int
|
||||
var maxRPS int64 // TODO: init boomer with this flag
|
||||
var requestIncreaseRate string // TODO: init boomer with this flag
|
||||
var runTasks string // TODO: init boomer with this flag
|
||||
var memoryProfile string
|
||||
var memoryProfileDuration time.Duration
|
||||
var cpuProfile string
|
||||
var cpuProfileDuration time.Duration
|
||||
var (
|
||||
masterHost string
|
||||
masterPort int
|
||||
maxRPS int64 // TODO: init boomer with this flag
|
||||
requestIncreaseRate string // TODO: init boomer with this flag
|
||||
runTasks string // TODO: init boomer with this flag
|
||||
memoryProfile string
|
||||
memoryProfileDuration time.Duration
|
||||
cpuProfile string
|
||||
cpuProfileDuration time.Duration
|
||||
)
|
||||
|
||||
func init() {
|
||||
RootCmd.AddCommand(boomCmd)
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/httprunner/httpboomer"
|
||||
@@ -18,23 +16,26 @@ var runCmd = &cobra.Command{
|
||||
$ httpboomer run examples/ # run testcases in specified folder`,
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
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
|
||||
for _, arg := range args {
|
||||
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() {
|
||||
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")
|
||||
}
|
||||
|
||||
@@ -28,15 +28,23 @@ type Runner struct {
|
||||
}
|
||||
|
||||
func (r *Runner) WithTestingT(t *testing.T) *Runner {
|
||||
log.Printf("[init] WithTestingT: %v", t)
|
||||
r.t = t
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *Runner) SetDebug(debug bool) *Runner {
|
||||
log.Printf("[init] SetDebug: %v", debug)
|
||||
r.debug = debug
|
||||
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 {
|
||||
for _, iTestCase := range testcases {
|
||||
testcase, err := iTestCase.ToTestCase()
|
||||
@@ -156,7 +164,6 @@ func (r *Runner) runStepRequest(step *TStep) (stepData *StepData, err error) {
|
||||
|
||||
// do request action
|
||||
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...)
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user