mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 07:26:55 +08:00
refactor: results dir
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
@@ -36,7 +35,7 @@ func DoCurl(args []string) (err error) {
|
|||||||
var curlResult CurlResult
|
var curlResult CurlResult
|
||||||
defer func() {
|
defer func() {
|
||||||
if saveTests {
|
if saveTests {
|
||||||
curlResultName := fmt.Sprintf("curl_result_%v.json", time.Now().Format("20060102150405"))
|
curlResultName := fmt.Sprintf("curl_result_%v.json", env.StartTimeStr)
|
||||||
curlResultPath := filepath.Join(env.RootDir, curlResultName)
|
curlResultPath := filepath.Join(env.RootDir, curlResultName)
|
||||||
err = builtin.Dump2JSON(curlResult, curlResultPath)
|
err = builtin.Dump2JSON(curlResult, curlResultPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ func DoDns(dnsOptions *DnsOptions, args []string) (err error) {
|
|||||||
var dnsResult DnsResult
|
var dnsResult DnsResult
|
||||||
defer func() {
|
defer func() {
|
||||||
if dnsOptions.SaveTests {
|
if dnsOptions.SaveTests {
|
||||||
dnsResultName := fmt.Sprintf("dns_result_%v.json", time.Now().Format("20060102150405"))
|
dnsResultName := fmt.Sprintf("dns_result_%v.json", env.StartTimeStr)
|
||||||
dnsResultPath := filepath.Join(env.RootDir, dnsResultName)
|
dnsResultPath := filepath.Join(env.RootDir, dnsResultName)
|
||||||
err = builtin.Dump2JSON(dnsResult, dnsResultPath)
|
err = builtin.Dump2JSON(dnsResult, dnsResultPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ func DoPing(pingOptions *PingOptions, args []string) (err error) {
|
|||||||
var pingResult PingResult
|
var pingResult PingResult
|
||||||
defer func() {
|
defer func() {
|
||||||
if pingOptions.SaveTests {
|
if pingOptions.SaveTests {
|
||||||
pingResultName := fmt.Sprintf("ping_result_%v.json", time.Now().Format("20060102150405"))
|
pingResultName := fmt.Sprintf("ping_result_%v.json", env.StartTimeStr)
|
||||||
pingResultPath := filepath.Join(env.RootDir, pingResultName)
|
pingResultPath := filepath.Join(env.RootDir, pingResultName)
|
||||||
err = builtin.Dump2JSON(pingResult, pingResultPath)
|
err = builtin.Dump2JSON(pingResult, pingResultPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func DoTraceRoute(traceRouteOptions *TraceRouteOptions, args []string) (err erro
|
|||||||
var traceRouteResult TraceRouteResult
|
var traceRouteResult TraceRouteResult
|
||||||
defer func() {
|
defer func() {
|
||||||
if traceRouteOptions.SaveTests {
|
if traceRouteOptions.SaveTests {
|
||||||
traceRouteResultName := fmt.Sprintf("traceroute_result_%v.json", time.Now().Format("20060102150405"))
|
traceRouteResultName := fmt.Sprintf("traceroute_result_%v.json", env.StartTimeStr)
|
||||||
traceRouteResultPath := filepath.Join(env.RootDir, traceRouteResultName)
|
traceRouteResultPath := filepath.Join(env.RootDir, traceRouteResultName)
|
||||||
err = builtin.Dump2JSON(traceRouteResult, traceRouteResultPath)
|
err = builtin.Dump2JSON(traceRouteResult, traceRouteResultPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ func DoTraceRoute(traceRouteOptions *TraceRouteOptions, args []string) (err erro
|
|||||||
var traceRouteResult TraceRouteResult
|
var traceRouteResult TraceRouteResult
|
||||||
defer func() {
|
defer func() {
|
||||||
if traceRouteOptions.SaveTests {
|
if traceRouteOptions.SaveTests {
|
||||||
traceRouteResultName := fmt.Sprintf("traceroute_result_%v.json", time.Now().Format("20060102150405"))
|
traceRouteResultName := fmt.Sprintf("traceroute_result_%v.json", env.StartTimeStr)
|
||||||
traceRouteResultPath := filepath.Join(env.RootDir, traceRouteResultName)
|
traceRouteResultPath := filepath.Join(env.RootDir, traceRouteResultName)
|
||||||
err = builtin.Dump2JSON(traceRouteResult, traceRouteResultPath)
|
err = builtin.Dump2JSON(traceRouteResult, traceRouteResultPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Vendored
+8
-2
@@ -3,6 +3,7 @@ package env
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -19,13 +20,17 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ResultsDir = "results"
|
ResultsDirName = "results"
|
||||||
|
ScreenshotsDirName = "screenshots"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
RootDir string
|
RootDir string
|
||||||
|
ResultsDir string
|
||||||
ResultsPath string
|
ResultsPath string
|
||||||
ScreenShotsPath string
|
ScreenShotsPath string
|
||||||
|
StartTime = time.Now()
|
||||||
|
StartTimeStr = StartTime.Format("20060102150405")
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -35,6 +40,7 @@ func init() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResultsDir = filepath.Join(ResultsDirName, StartTimeStr)
|
||||||
ResultsPath = filepath.Join(RootDir, ResultsDir)
|
ResultsPath = filepath.Join(RootDir, ResultsDir)
|
||||||
ScreenShotsPath = filepath.Join(ResultsPath, "screenshots")
|
ScreenShotsPath = filepath.Join(ResultsPath, ScreenshotsDirName)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,10 +92,10 @@ func CreateScaffold(projectName string, pluginType PluginType, venv string, forc
|
|||||||
if err := builtin.CreateFolder(filepath.Join(projectName, "testcases")); err != nil {
|
if err := builtin.CreateFolder(filepath.Join(projectName, "testcases")); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := builtin.CreateFolder(filepath.Join(projectName, env.ResultsDir)); err != nil {
|
if err := builtin.CreateFolder(filepath.Join(projectName, env.ResultsDirName)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := builtin.CreateFile(filepath.Join(projectName, env.ResultsDir, ".keep"), ""); err != nil {
|
if err := builtin.CreateFile(filepath.Join(projectName, env.ResultsDirName, ".keep"), ""); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
@@ -188,7 +187,7 @@ type TCaseConverter struct {
|
|||||||
func (c *TCaseConverter) genOutputPath(suffix string) string {
|
func (c *TCaseConverter) genOutputPath(suffix string) string {
|
||||||
var outFileFullName string
|
var outFileFullName string
|
||||||
if curlCmd := strings.TrimSpace(c.InputSample); strings.HasPrefix(curlCmd, "curl ") {
|
if curlCmd := strings.TrimSpace(c.InputSample); strings.HasPrefix(curlCmd, "curl ") {
|
||||||
outFileFullName = fmt.Sprintf("curl_%v_test%v", time.Now().Format("20060102150405"), suffix)
|
outFileFullName = fmt.Sprintf("curl_%v_test%v", env.StartTimeStr, suffix)
|
||||||
if c.OutputDir != "" {
|
if c.OutputDir != "" {
|
||||||
return filepath.Join(c.OutputDir, outFileFullName)
|
return filepath.Join(c.OutputDir, outFileFullName)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+2
-3
@@ -208,7 +208,6 @@ type DriverExt struct {
|
|||||||
doneMjpegStream chan bool
|
doneMjpegStream chan bool
|
||||||
scale float64
|
scale float64
|
||||||
ocrService OCRService // used to get text from image
|
ocrService OCRService // used to get text from image
|
||||||
StartTime time.Time // used to associate screenshots name
|
|
||||||
ScreenShots []string // save screenshots path
|
ScreenShots []string // save screenshots path
|
||||||
|
|
||||||
CVArgs
|
CVArgs
|
||||||
@@ -657,8 +656,8 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
case CtlScreenShot:
|
case CtlScreenShot:
|
||||||
// take snapshot
|
// take snapshot
|
||||||
log.Info().Msg("take snapshot for current screen")
|
log.Info().Msg("take snapshot for current screen")
|
||||||
screenshotPath, err := dExt.ScreenShot(fmt.Sprintf("%d_screenshot_%d",
|
screenshotPath, err := dExt.ScreenShot(fmt.Sprintf("screenshot_%d",
|
||||||
dExt.StartTime.Unix(), time.Now().Unix()))
|
time.Now().Unix()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "take screenshot failed")
|
return errors.Wrap(err, "take screenshot failed")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -349,9 +349,7 @@ func (dev *IOSDevice) StartPerf() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
dev.perfFile = filepath.Join(env.ResultsPath,
|
dev.perfFile = filepath.Join(env.ResultsPath, "perf.data")
|
||||||
fmt.Sprintf("perf_%s.log", time.Now().Format("20060102150405")))
|
|
||||||
|
|
||||||
log.Info().Str("perfFile", dev.perfFile).Msg("create perf file")
|
log.Info().Str("perfFile", dev.perfFile).Msg("create perf file")
|
||||||
file, err := os.OpenFile(dev.perfFile,
|
file, err := os.OpenFile(dev.perfFile,
|
||||||
os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0o755)
|
os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0o755)
|
||||||
@@ -395,9 +393,7 @@ func (dev *IOSDevice) StartPcap() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
dev.pcapFile = filepath.Join(env.ResultsPath,
|
dev.pcapFile = filepath.Join(env.ResultsPath, "dump.pcap")
|
||||||
fmt.Sprintf("dump_%s.pcap", time.Now().Format("20060102150405")))
|
|
||||||
|
|
||||||
log.Info().Str("pcapFile", dev.pcapFile).Msg("create pcap file")
|
log.Info().Str("pcapFile", dev.pcapFile).Msg("create pcap file")
|
||||||
file, err := os.OpenFile(dev.pcapFile,
|
file, err := os.OpenFile(dev.pcapFile,
|
||||||
os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0o755)
|
os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0o755)
|
||||||
|
|||||||
@@ -552,7 +552,6 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
uiDriver.StartTime = s.startTime
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
attachments := make(map[string]interface{})
|
attachments := make(map[string]interface{})
|
||||||
@@ -598,7 +597,7 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err
|
|||||||
|
|
||||||
// take snapshot
|
// take snapshot
|
||||||
screenshotPath, err := uiDriver.ScreenShot(
|
screenshotPath, err := uiDriver.ScreenShot(
|
||||||
fmt.Sprintf("%d_validate_%d", uiDriver.StartTime.Unix(), time.Now().Unix()))
|
fmt.Sprintf("validate_%d", time.Now().Unix()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn().Err(err).Str("step", step.Name).Msg("take screenshot failed")
|
log.Warn().Err(err).Str("step", step.Name).Msg("take screenshot failed")
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+3
-3
@@ -27,7 +27,7 @@ func newOutSummary() *Summary {
|
|||||||
Success: true,
|
Success: true,
|
||||||
Stat: &Stat{},
|
Stat: &Stat{},
|
||||||
Time: &TestCaseTime{
|
Time: &TestCaseTime{
|
||||||
StartAt: time.Now(),
|
StartAt: env.StartTime,
|
||||||
},
|
},
|
||||||
Platform: platForm,
|
Platform: platForm,
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ func (s *Summary) genHTMLReport() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
reportPath := filepath.Join(reportsDir, fmt.Sprintf("report-%v.html", s.Time.StartAt.Unix()))
|
reportPath := filepath.Join(reportsDir, "report.html")
|
||||||
file, err := os.OpenFile(reportPath, os.O_WRONLY|os.O_CREATE, 0o666)
|
file, err := os.OpenFile(reportPath, os.O_WRONLY|os.O_CREATE, 0o666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("open file failed")
|
log.Error().Err(err).Msg("open file failed")
|
||||||
@@ -103,7 +103,7 @@ func (s *Summary) genSummary() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
summaryPath := filepath.Join(reportsDir, fmt.Sprintf("summary-%v.json", s.Time.StartAt.Unix()))
|
summaryPath := filepath.Join(reportsDir, "summary.json")
|
||||||
err = builtin.Dump2JSON(s, summaryPath)
|
err = builtin.Dump2JSON(s, summaryPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user