change: remove curl

This commit is contained in:
debugtalk
2022-12-23 18:57:15 +08:00
parent 0abd64abc2
commit 4734b35ac4
4 changed files with 0 additions and 87 deletions

View File

@@ -92,7 +92,6 @@ Available Commands:
build build plugin for testing
completion Generate the autocompletion script for the specified shell
convert convert multiple source format to HttpRunner JSON/YAML/gotest/pytest cases
curl run integrated curl command
dns DNS resolution for different source and record types
help Help about any command
ios simple utils for ios device management

View File

@@ -85,7 +85,6 @@ Available Commands:
build build plugin for testing
completion Generate the autocompletion script for the specified shell
convert convert multiple source format to HttpRunner JSON/YAML/gotest/pytest cases
curl run integrated curl command
dns DNS resolution for different source and record types
help Help about any command
ios simple utils for ios device management

View File

@@ -61,19 +61,6 @@ var traceRouteCmd = &cobra.Command{
},
}
var curlCmd = &cobra.Command{
Use: "curl $url",
Short: "run integrated curl command",
Args: cobra.MinimumNArgs(1),
DisableFlagParsing: true,
PreRun: func(cmd *cobra.Command, args []string) {
setLogLevel(logLevel)
},
RunE: func(cmd *cobra.Command, args []string) error {
return dial.DoCurl(args)
},
}
func init() {
rootCmd.AddCommand(pingCmd)
pingCmd.Flags().IntVarP(&pingOptions.Count, "count", "c", 10, "Stop after sending (and receiving) N packets")
@@ -91,6 +78,4 @@ func init() {
traceRouteCmd.Flags().IntVarP(&traceRouteOptions.MaxTTL, "max-hops", "m", 30, "Set the max number of hops (max TTL to be reached)")
traceRouteCmd.Flags().IntVarP(&traceRouteOptions.Queries, "queries", "q", 1, "Set the number of probes per each hop")
traceRouteCmd.Flags().BoolVar(&traceRouteOptions.SaveTests, "save-tests", false, "Save traceroute result as json")
rootCmd.AddCommand(curlCmd)
}

View File

@@ -1,70 +0,0 @@
package dial
import (
"bytes"
"fmt"
"path/filepath"
"github.com/rs/zerolog/log"
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
"github.com/httprunner/httprunner/v4/hrp/internal/env"
"github.com/httprunner/httprunner/v4/hrp/internal/myexec"
)
const (
normalResult = "STDOUT"
errorResult = "STDERR"
failedResult = "FAILED"
)
type CurlResult struct {
Result string `json:"result"`
ErrorMsg string `json:"errorMsg"`
ResultType string `json:"resultType"`
}
func DoCurl(args []string) (err error) {
var saveTests bool
for i, arg := range args {
if arg == "--save-tests" {
args = append(args[:i], args[i+1:]...)
saveTests = true
}
}
var curlResult CurlResult
defer func() {
if saveTests {
curlResultName := fmt.Sprintf("curl_result_%v.json", env.StartTimeStr)
curlResultPath := filepath.Join(env.RootDir, curlResultName)
err = builtin.Dump2JSON(curlResult, curlResultPath)
if err != nil {
log.Error().Err(err).Msg("save dns resolution result failed")
}
}
}()
cmd := myexec.Command("curl", args...)
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err = cmd.Run()
if err != nil {
log.Error().Err(err).Msgf("fail to run curl command")
curlResult.ErrorMsg = err.Error()
curlResult.Result = stderr.String()
curlResult.ResultType = errorResult
return
}
if stdout.String() != "" {
fmt.Println(stdout.String())
curlResult.Result = stdout.String()
curlResult.ResultType = normalResult
} else if stderr.String() != "" {
fmt.Println(stderr.String())
curlResult.ErrorMsg = stderr.String()
curlResult.ResultType = errorResult
}
return
}