mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-10 23:12:41 +08:00
refactor: get current dir
This commit is contained in:
@@ -3,13 +3,13 @@ package dial
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
@@ -36,9 +36,8 @@ func DoCurl(args []string) (err error) {
|
||||
var curlResult CurlResult
|
||||
defer func() {
|
||||
if saveTests {
|
||||
dir, _ := os.Getwd()
|
||||
curlResultName := fmt.Sprintf("curl_result_%v.json", time.Now().Format("20060102150405"))
|
||||
curlResultPath := filepath.Join(dir, curlResultName)
|
||||
curlResultPath := filepath.Join(env.RootDir, curlResultName)
|
||||
err = builtin.Dump2JSON(curlResult, curlResultPath)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("save dns resolution result failed")
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -17,6 +16,7 @@ import (
|
||||
"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/json"
|
||||
)
|
||||
|
||||
@@ -210,9 +210,8 @@ func DoDns(dnsOptions *DnsOptions, args []string) (err error) {
|
||||
var dnsResult DnsResult
|
||||
defer func() {
|
||||
if dnsOptions.SaveTests {
|
||||
dir, _ := os.Getwd()
|
||||
dnsResultName := fmt.Sprintf("dns_result_%v.json", time.Now().Format("20060102150405"))
|
||||
dnsResultPath := filepath.Join(dir, dnsResultName)
|
||||
dnsResultPath := filepath.Join(env.RootDir, dnsResultName)
|
||||
err = builtin.Dump2JSON(dnsResult, dnsResultPath)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("save dns resolution result failed")
|
||||
|
||||
@@ -3,7 +3,6 @@ package dial
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -13,6 +12,7 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/env"
|
||||
)
|
||||
|
||||
type PingOptions struct {
|
||||
@@ -46,9 +46,8 @@ func DoPing(pingOptions *PingOptions, args []string) (err error) {
|
||||
var pingResult PingResult
|
||||
defer func() {
|
||||
if pingOptions.SaveTests {
|
||||
dir, _ := os.Getwd()
|
||||
pingResultName := fmt.Sprintf("ping_result_%v.json", time.Now().Format("20060102150405"))
|
||||
pingResultPath := filepath.Join(dir, pingResultName)
|
||||
pingResultPath := filepath.Join(env.RootDir, pingResultName)
|
||||
err = builtin.Dump2JSON(pingResult, pingResultPath)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("save ping result failed")
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@@ -17,6 +16,7 @@ import (
|
||||
"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"
|
||||
)
|
||||
|
||||
@@ -34,9 +34,8 @@ func DoTraceRoute(traceRouteOptions *TraceRouteOptions, args []string) (err erro
|
||||
var traceRouteResult TraceRouteResult
|
||||
defer func() {
|
||||
if traceRouteOptions.SaveTests {
|
||||
dir, _ := os.Getwd()
|
||||
traceRouteResultName := fmt.Sprintf("traceroute_result_%v.json", time.Now().Format("20060102150405"))
|
||||
traceRouteResultPath := filepath.Join(dir, traceRouteResultName)
|
||||
traceRouteResultPath := filepath.Join(env.RootDir, traceRouteResultName)
|
||||
err = builtin.Dump2JSON(traceRouteResult, traceRouteResultPath)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("save traceroute result failed")
|
||||
|
||||
@@ -32,9 +32,8 @@ func DoTraceRoute(traceRouteOptions *TraceRouteOptions, args []string) (err erro
|
||||
var traceRouteResult TraceRouteResult
|
||||
defer func() {
|
||||
if traceRouteOptions.SaveTests {
|
||||
dir, _ := os.Getwd()
|
||||
traceRouteResultName := fmt.Sprintf("traceroute_result_%v.json", time.Now().Format("20060102150405"))
|
||||
traceRouteResultPath := filepath.Join(dir, traceRouteResultName)
|
||||
traceRouteResultPath := filepath.Join(env.RootDir, traceRouteResultName)
|
||||
err = builtin.Dump2JSON(traceRouteResult, traceRouteResultPath)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("save traceroute result failed")
|
||||
|
||||
Reference in New Issue
Block a user