mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-30 21:09:36 +08:00
fix: get config
This commit is contained in:
@@ -3,6 +3,7 @@ package config
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
@@ -17,40 +18,55 @@ const (
|
||||
ActionLogDirName = "action_log"
|
||||
)
|
||||
|
||||
var (
|
||||
type Config struct {
|
||||
RootDir string
|
||||
ResultsDir string
|
||||
ResultsPath string
|
||||
DownloadsPath string
|
||||
ScreenShotsPath string
|
||||
StartTime = time.Now()
|
||||
StartTimeStr = StartTime.Format("20060102150405")
|
||||
StartTime time.Time
|
||||
ActionLogFilePath string
|
||||
DeviceActionLogFilePath string
|
||||
}
|
||||
|
||||
var (
|
||||
globalConfig *Config
|
||||
once sync.Once
|
||||
)
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
RootDir, err = os.Getwd()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
func GetConfig() *Config {
|
||||
once.Do(func() {
|
||||
cfg := &Config{
|
||||
StartTime: time.Now(),
|
||||
}
|
||||
|
||||
ResultsDir = filepath.Join(ResultsDirName, StartTimeStr)
|
||||
ResultsPath = filepath.Join(RootDir, ResultsDir)
|
||||
DownloadsPath = filepath.Join(RootDir, filepath.Join(DownloadsDirName, StartTimeStr))
|
||||
ScreenShotsPath = filepath.Join(ResultsPath, ScreenshotsDirName)
|
||||
ActionLogFilePath = filepath.Join(ResultsDir, ActionLogDirName)
|
||||
DeviceActionLogFilePath = "/sdcard/Android/data/io.appium.uiautomator2.server/files/hodor"
|
||||
var err error
|
||||
cfg.RootDir, err = os.Getwd()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// create results directory
|
||||
if err := builtin.EnsureFolderExists(ResultsPath); err != nil {
|
||||
log.Fatal().Err(err).Msg("create results directory failed")
|
||||
}
|
||||
if err := builtin.EnsureFolderExists(DownloadsPath); err != nil {
|
||||
log.Fatal().Err(err).Msg("create results directory failed")
|
||||
}
|
||||
if err := builtin.EnsureFolderExists(ScreenShotsPath); err != nil {
|
||||
log.Fatal().Err(err).Msg("create screenshots directory failed")
|
||||
}
|
||||
startTimeStr := cfg.StartTime.Format("20060102150405")
|
||||
cfg.ResultsDir = filepath.Join(ResultsDirName, startTimeStr)
|
||||
cfg.ResultsPath = filepath.Join(cfg.RootDir, cfg.ResultsDir)
|
||||
cfg.DownloadsPath = filepath.Join(cfg.RootDir, filepath.Join(DownloadsDirName, startTimeStr))
|
||||
cfg.ScreenShotsPath = filepath.Join(cfg.ResultsPath, ScreenshotsDirName)
|
||||
cfg.ActionLogFilePath = filepath.Join(cfg.ResultsDir, ActionLogDirName)
|
||||
cfg.DeviceActionLogFilePath = "/sdcard/Android/data/io.appium.uiautomator2.server/files/hodor"
|
||||
|
||||
// create results directory
|
||||
if err := builtin.EnsureFolderExists(cfg.ResultsPath); err != nil {
|
||||
log.Fatal().Err(err).Msg("create results directory failed")
|
||||
}
|
||||
if err := builtin.EnsureFolderExists(cfg.DownloadsPath); err != nil {
|
||||
log.Fatal().Err(err).Msg("create downloads directory failed")
|
||||
}
|
||||
if err := builtin.EnsureFolderExists(cfg.ScreenShotsPath); err != nil {
|
||||
log.Fatal().Err(err).Msg("create screenshots directory failed")
|
||||
}
|
||||
|
||||
globalConfig = cfg
|
||||
})
|
||||
|
||||
return globalConfig
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
v5.0.0+2503041818
|
||||
v5.0.0+2503041939
|
||||
|
||||
Reference in New Issue
Block a user