mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-25 10:20:11 +08:00
refactor: rename command
This commit is contained in:
54
httpboomer/cmd/boom.go
Normal file
54
httpboomer/cmd/boom.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/httprunner/httpboomer"
|
||||
)
|
||||
|
||||
// boomCmd represents the boom command
|
||||
var boomCmd = &cobra.Command{
|
||||
Use: "boom",
|
||||
Short: "run load test with boomer",
|
||||
Long: `run yaml/json testcase files for load test`,
|
||||
Example: ` $ httpboomer boom demo.json # run specified json testcase file
|
||||
$ httpboomer boom demo.yaml # run specified yaml testcase file
|
||||
$ httpboomer boom examples/ # run testcases in specified folder`,
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var paths []httpboomer.ITestCase
|
||||
for _, arg := range args {
|
||||
paths = append(paths, &httpboomer.TestCasePath{Path: arg})
|
||||
}
|
||||
boomer := httpboomer.NewBoomer(masterHost, masterPort)
|
||||
boomer.EnableCPUProfile(cpuProfile, cpuProfileDuration)
|
||||
boomer.EnableMemoryProfile(memoryProfile, memoryProfileDuration)
|
||||
boomer.Run(paths...)
|
||||
},
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(boomCmd)
|
||||
|
||||
boomCmd.Flags().Int64Var(&maxRPS, "max-rps", 0, "Max RPS that boomer can generate, disabled by default.")
|
||||
boomCmd.Flags().StringVar(&requestIncreaseRate, "request-increase-rate", "-1", "Request increase rate, disabled by default.")
|
||||
boomCmd.Flags().StringVar(&runTasks, "run-tasks", "", "Run tasks without connecting to the master, multiply tasks is separated by comma. Usually, it's for debug purpose.")
|
||||
boomCmd.Flags().StringVar(&masterHost, "master-host", "127.0.0.1", "Host or IP address of locust master for distributed load testing.")
|
||||
boomCmd.Flags().IntVar(&masterPort, "master-port", 5557, "The port to connect to that is used by the locust master for distributed load testing.")
|
||||
boomCmd.Flags().StringVar(&memoryProfile, "mem-profile", "", "Enable memory profiling.")
|
||||
boomCmd.Flags().DurationVar(&memoryProfileDuration, "mem-profile-duration", 30*time.Second, "Memory profile duration.")
|
||||
boomCmd.Flags().StringVar(&cpuProfile, "cpu-profile", "", "Enable CPU profiling.")
|
||||
boomCmd.Flags().DurationVar(&cpuProfileDuration, "cpu-profile-duration", 30*time.Second, "CPU profile duration.")
|
||||
}
|
||||
15
httpboomer/cmd/gen_doc.go
Normal file
15
httpboomer/cmd/gen_doc.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package cmd
|
||||
|
||||
// import (
|
||||
// "log"
|
||||
|
||||
// "github.com/spf13/cobra/doc"
|
||||
// )
|
||||
|
||||
// func main() {
|
||||
|
||||
// err := doc.GenMarkdownTree(rootCmd, "/tmp")
|
||||
// if err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
// }
|
||||
40
httpboomer/cmd/har2case.go
Normal file
40
httpboomer/cmd/har2case.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/httprunner/httpboomer/har2case"
|
||||
)
|
||||
|
||||
// har2caseCmd represents the har2case command
|
||||
var har2caseCmd = &cobra.Command{
|
||||
Use: "har2case path...",
|
||||
Short: "Convert HAR to json/yaml testcase files",
|
||||
Long: `Convert HAR to json/yaml testcase files`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("har2case called")
|
||||
var outputFiles []string
|
||||
for _, arg := range args {
|
||||
jsonPath, _ := har2case.NewHAR(arg).GenJSON()
|
||||
outputFiles = append(outputFiles, jsonPath)
|
||||
}
|
||||
log.Printf("%v", outputFiles)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(har2caseCmd)
|
||||
|
||||
// Here you will define your flags and configuration settings.
|
||||
|
||||
// Cobra supports Persistent Flags which will work for this command
|
||||
// and all subcommands, e.g.:
|
||||
// har2caseCmd.PersistentFlags().String("foo", "", "A help for foo")
|
||||
|
||||
// Cobra supports local flags which will only run when this command
|
||||
// is called directly, e.g.:
|
||||
// har2caseCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||
}
|
||||
31
httpboomer/cmd/root.go
Normal file
31
httpboomer/cmd/root.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/httprunner/httpboomer"
|
||||
)
|
||||
|
||||
// rootCmd represents the base command when called without any subcommands
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "httpboomer",
|
||||
Short: "One-stop solution for HTTP(S) testing.",
|
||||
Long: `HttpBoomer is the next generation for HttpRunner. Enjoy! ✨ 🚀 ✨
|
||||
|
||||
License: Apache-2.0
|
||||
Github: https://github.com/httprunner/httpboomer
|
||||
Copyright 2021 debugtalk`,
|
||||
Version: httpboomer.VERSION,
|
||||
}
|
||||
|
||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||
func Execute() {
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
40
httpboomer/cmd/run.go
Normal file
40
httpboomer/cmd/run.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/httprunner/httpboomer"
|
||||
)
|
||||
|
||||
// runCmd represents the run command
|
||||
var runCmd = &cobra.Command{
|
||||
Use: "run path...",
|
||||
Short: "run API test",
|
||||
Long: `run yaml/json testcase files for API test`,
|
||||
Example: ` $ httpboomer run demo.json # run specified json testcase file
|
||||
$ httpboomer run demo.yaml # run specified yaml testcase file
|
||||
$ 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...)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(runCmd)
|
||||
runCmd.Flags().BoolP("silent", "s", false, "Disable logging request & response details")
|
||||
// runCmd.Flags().BoolP("gen-html-report", "r", false, "Generate HTML report")
|
||||
}
|
||||
Reference in New Issue
Block a user