refactor: config results path

This commit is contained in:
lilong.129
2025-06-15 22:55:02 +08:00
parent c62913ba1a
commit a78ba90d33
7 changed files with 113 additions and 38 deletions

View File

@@ -12,21 +12,32 @@ import (
)
const (
ResultsDirName = "results"
DownloadsDirName = "downloads"
ScreenshotsDirName = "screenshots"
ActionLogDirName = "action_log"
// results directory names
ResultsDirName = "results" // $PWD/results/
DownloadsDirName = "downloads" // $PWD/results/20060102150405/downloads/
ScreenshotsDirName = "screenshots" // $PWD/results/20060102150405/screenshots/
ActionLogDirName = "action_log" // $PWD/results/20060102150405/action_log/
// results file names
SummaryFileName = "hrp_summary.json" // $PWD/results/20060102150405/hrp_summary.json
LogFileName = "hrp.log" // $PWD/results/20060102150405/hrp.log
ReportFileName = "report.html" // $PWD/results/20060102150405/report.html
// mobile device path
DeviceActionLogFilePath = "/sdcard/Android/data/io.appium.uiautomator2.server/files/hodor"
)
type Config struct {
RootDir string
resultsPath string
downloadsPath string
screenShotsPath string
StartTime time.Time
ActionLogFilePath string
DeviceActionLogFilePath string
mu sync.Mutex
StartTime time.Time
RootDir string
resultsPath string
downloadsPath string
screenShotsPath string
summaryFilePath string
logFilePath string
reportFilePath string
actionLogDirPath string
mu sync.Mutex
}
var (
@@ -51,9 +62,10 @@ func GetConfig() *Config {
cfg.resultsPath = filepath.Join(cfg.RootDir, resultsDir)
cfg.downloadsPath = filepath.Join(cfg.RootDir, filepath.Join(DownloadsDirName, startTimeStr))
cfg.screenShotsPath = filepath.Join(cfg.resultsPath, ScreenshotsDirName)
cfg.ActionLogFilePath = filepath.Join(resultsDir, ActionLogDirName)
cfg.DeviceActionLogFilePath = "/sdcard/Android/data/io.appium.uiautomator2.server/files/hodor"
cfg.actionLogDirPath = filepath.Join(resultsDir, ActionLogDirName)
cfg.logFilePath = filepath.Join(cfg.resultsPath, LogFileName)
cfg.summaryFilePath = filepath.Join(cfg.resultsPath, SummaryFileName)
cfg.reportFilePath = filepath.Join(cfg.resultsPath, ReportFileName)
globalConfig = cfg
})
@@ -107,3 +119,58 @@ func (c *Config) ScreenShotsPath() string {
}
return c.screenShotsPath
}
// $PWD/results/20060102150405/action_log/
func (c *Config) ActionLogDirPath() string {
c.mu.Lock()
defer c.mu.Unlock()
// Check if directory exists, create if it doesn't
if _, err := os.Stat(c.actionLogDirPath); os.IsNotExist(err) {
if err := builtin.EnsureFolderExists(c.actionLogDirPath); err != nil {
log.Fatal().Err(err).Str("path", c.actionLogDirPath).Msg("failed to create action log directory")
} else {
log.Info().Str("path", c.actionLogDirPath).Msg("created action log folder")
}
}
return c.actionLogDirPath
}
// $PWD/results/20060102150405/hrp_summary.json
func (c *Config) SummaryFilePath() string {
c.mu.Lock()
defer c.mu.Unlock()
if c.summaryFilePath != "" {
return c.summaryFilePath
}
c.summaryFilePath = filepath.Join(c.ResultsPath(), SummaryFileName)
return c.summaryFilePath
}
// $PWD/results/20060102150405/hrp.log
func (c *Config) LogFilePath() string {
c.mu.Lock()
defer c.mu.Unlock()
if c.logFilePath != "" {
return c.logFilePath
}
c.logFilePath = filepath.Join(c.ResultsPath(), LogFileName)
return c.logFilePath
}
// $PWD/results/20060102150405/report.html
func (c *Config) ReportFilePath() string {
c.mu.Lock()
defer c.mu.Unlock()
if c.reportFilePath != "" {
return c.reportFilePath
}
c.reportFilePath = filepath.Join(c.ResultsPath(), ReportFileName)
return c.reportFilePath
}

View File

@@ -1 +1 @@
v5.0.0-beta-2506150047
v5.0.0-beta-2506152331