提交 315d2746 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

parse pytest allure results

上级 f9fb7716
...@@ -234,4 +234,4 @@ upload_to: ...@@ -234,4 +234,4 @@ upload_to:
@echo 'upload...' @echo 'upload...'
@find ${QINIU_DIR} -name ".DS_Store" -type f -delete @find ${QINIU_DIR} -name ".DS_Store" -type f -delete
@qshell qupload2 --src-dir=${QINIU_DIR} --bucket=download --thread-count=10 --log-file=qshell.log \ @qshell qupload2 --src-dir=${QINIU_DIR} --bucket=download --thread-count=10 --log-file=qshell.log \
--skip-path-prefixes=zz,zd,zmanager,driver --rescan-local --overwrite --check-hash --skip-path-prefixes=zv,zd,zmanager,driver --rescan-local --overwrite --check-hash
...@@ -2,6 +2,7 @@ package main ...@@ -2,6 +2,7 @@ package main
import ( import (
"flag" "flag"
commConsts "github.com/easysoft/zentaoatf/internal/pkg/consts"
websocketHelper "github.com/easysoft/zentaoatf/internal/pkg/helper/websocket" websocketHelper "github.com/easysoft/zentaoatf/internal/pkg/helper/websocket"
"github.com/easysoft/zentaoatf/internal/server/core/web" "github.com/easysoft/zentaoatf/internal/server/core/web"
logUtils "github.com/easysoft/zentaoatf/pkg/lib/log" logUtils "github.com/easysoft/zentaoatf/pkg/lib/log"
...@@ -37,6 +38,8 @@ func main() { ...@@ -37,6 +38,8 @@ func main() {
logUtils.PrintVersion(AppVersion, BuildTime, GoVersion, GitHash) logUtils.PrintVersion(AppVersion, BuildTime, GoVersion, GitHash)
return return
default: default:
commConsts.ExecFrom = commConsts.FromClient
webServer := web.Init(port) webServer := web.Init(port)
if webServer == nil { if webServer == nil {
return return
......
...@@ -53,6 +53,7 @@ require ( ...@@ -53,6 +53,7 @@ require (
go.uber.org/zap v1.21.0 // indirect go.uber.org/zap v1.21.0 // indirect
golang.org/x/text v0.3.7 golang.org/x/text v0.3.7
gopkg.in/ini.v1 v1.63.0 gopkg.in/ini.v1 v1.63.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gorm.io/driver/sqlite v1.2.6 gorm.io/driver/sqlite v1.2.6
gorm.io/gorm v1.22.3 gorm.io/gorm v1.22.3
gorm.io/plugin/dbresolver v1.1.0 gorm.io/plugin/dbresolver v1.1.0
......
...@@ -14,7 +14,6 @@ const ( ...@@ -14,7 +14,6 @@ const (
ConfigDir = "conf" ConfigDir = "conf"
ConfigFile = "ztf.conf" ConfigFile = "ztf.conf"
LogDirName = "log" LogDirName = "log"
LogBakDirName = "log-bak"
ExtNameSuite = "cs" ExtNameSuite = "cs"
LogText = "log.txt" LogText = "log.txt"
ResultText = "result.txt" ResultText = "result.txt"
......
package commConsts package commConsts
import (
"github.com/awesome-gocui/gocui"
)
var ( var (
LanguageZh = "zh" LanguageZh = "zh"
LanguageEn = "en" LanguageEn = "en"
...@@ -23,8 +19,6 @@ var ( ...@@ -23,8 +19,6 @@ var (
) )
var ( var (
Cui *gocui.Gui
MainViewHeight int
ConfigPath string ConfigPath string
ServerWorkDir string ServerWorkDir string
ServerWorkspaceDir string ServerWorkspaceDir string
......
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
commConsts "github.com/easysoft/zentaoatf/internal/pkg/consts" commConsts "github.com/easysoft/zentaoatf/internal/pkg/consts"
commonUtils "github.com/easysoft/zentaoatf/pkg/lib/common" commonUtils "github.com/easysoft/zentaoatf/pkg/lib/common"
logUtils "github.com/easysoft/zentaoatf/pkg/lib/log" logUtils "github.com/easysoft/zentaoatf/pkg/lib/log"
"gopkg.in/natefinch/lumberjack.v2"
"log" "log"
"net/url" "net/url"
"os" "os"
...@@ -27,38 +28,39 @@ func InitLog() { ...@@ -27,38 +28,39 @@ func InitLog() {
zapConfig := getLogConfig() zapConfig := getLogConfig()
// print to console // print to console and info、err files
var err error var err error
zapConfig.EncoderConfig.EncodeLevel = nil zapConfig.EncoderConfig.EncodeLevel = nil
zapConfig.DisableCaller = true zapConfig.DisableCaller = true
zapConfig.EncoderConfig.TimeKey = "" zapConfig.EncoderConfig.TimeKey = ""
logUtils.LoggerStandard, err = zapConfig.Build() logUtils.LoggerStandard, err = zapConfig.Build(zap.WrapCore(zapCore))
if err != nil { if err != nil {
log.Println("init console logger fail " + err.Error()) log.Println("init console logger fail " + err.Error())
} }
// print to console without detail // print to console and info、err files without stacktrace detail
// by set DisableStacktrace to true
zapConfig.DisableStacktrace = true zapConfig.DisableStacktrace = true
logUtils.LoggerExecConsole, err = zapConfig.Build() logUtils.LoggerExecConsole, err = zapConfig.Build(zap.WrapCore(zapCore))
if err != nil { if err != nil {
log.Println("init exec console logger fail " + err.Error()) log.Println("init exec console logger fail " + err.Error())
} }
} }
// 执行日志,用于具体的测试执行 // write exec results by using zap log
func InitExecLog(workspacePath string) { func InitExecLog(workspacePath string) {
commConsts.ExecLogDir = logUtils.GetLogDir(workspacePath) commConsts.ExecLogDir = logUtils.GetLogDir(workspacePath)
config := getLogConfig() config := getLogConfig()
config.EncoderConfig.EncodeLevel = nil config.EncoderConfig.EncodeLevel = nil
// print to test log file // print to test log file
logPath := filepath.Join(commConsts.ExecLogDir, commConsts.LogText) logPathInfo := filepath.Join(commConsts.ExecLogDir, commConsts.LogText)
if commonUtils.IsWin() { if commonUtils.IsWin() {
logPath = filepath.Join(WinFileSchema, logPath) logPathInfo = filepath.Join(WinFileSchema, logPathInfo)
zap.RegisterSink("winfile", newWinFileSink) zap.RegisterSink("winfile", newWinFileSink)
} }
config.OutputPaths = []string{logPath} config.OutputPaths = []string{logPathInfo}
var err error var err error
logUtils.LoggerExecFile, err = config.Build() logUtils.LoggerExecFile, err = config.Build()
...@@ -128,19 +130,12 @@ func getLogConfig() (config zap.Config) { ...@@ -128,19 +130,12 @@ func getLogConfig() (config zap.Config) {
StacktraceKey: "stacktrace", StacktraceKey: "stacktrace",
LineEnding: zapcore.DefaultLineEnding, LineEnding: zapcore.DefaultLineEnding,
//EncodeLevel: zapcore.LowercaseLevelEncoder, // 小写编码器 //EncodeLevel: zapcore.LowercaseLevelEncoder, // 小写编码器
EncodeTime: zapcore.TimeEncoderOfLayout("2006-01-02 15:04:05.000"),
EncodeLevel: zapcore.CapitalColorLevelEncoder, //这里可以指定颜色 EncodeLevel: zapcore.CapitalColorLevelEncoder, //这里可以指定颜色
EncodeTime: zapcore.ISO8601TimeEncoder, // ISO8601 UTC 时间格式
EncodeDuration: zapcore.SecondsDurationEncoder, EncodeDuration: zapcore.SecondsDurationEncoder,
EncodeCaller: zapcore.FullCallerEncoder, // 全路径编码器 EncodeCaller: zapcore.FullCallerEncoder, // 全路径编码器
} }
logPathInfo := filepath.Join(CONFIG.Zap.Director, "info.log")
logPathErr := filepath.Join(CONFIG.Zap.Director, "err.log")
if commonUtils.IsWin() {
logPathInfo = filepath.Join(WinFileSchema, logPathInfo)
logPathErr = filepath.Join(WinFileSchema, logPathErr)
}
config = zap.Config{ config = zap.Config{
Level: zap.NewAtomicLevelAt(level), // 日志级别 Level: zap.NewAtomicLevelAt(level), // 日志级别
Development: true, // 开发模式,堆栈跟踪 Development: true, // 开发模式,堆栈跟踪
...@@ -149,11 +144,18 @@ func getLogConfig() (config zap.Config) { ...@@ -149,11 +144,18 @@ func getLogConfig() (config zap.Config) {
//InitialFields: map[string]interface{}{"test_machine": "pc1"}, // 初始化字段 //InitialFields: map[string]interface{}{"test_machine": "pc1"}, // 初始化字段
} }
config.EncoderConfig.EncodeLevel = zapcore.LowercaseColorLevelEncoder //这里可以指定颜色 config.EncoderConfig.EncodeLevel = zapcore.LowercaseColorLevelEncoder //这里可以指定颜色
if commonUtils.IsWin() { //if commonUtils.IsWin() {
zap.RegisterSink("winfile", newWinFileSink) // zap.RegisterSink("winfile", newWinFileSink)
} //}
config.OutputPaths = []string{"stdout", logPathInfo} //
config.ErrorOutputPaths = []string{"stderr", logPathErr} //logPathInfo := filepath.Join(CONFIG.Zap.Director, "info.log")
//logPathErr := filepath.Join(CONFIG.Zap.Director, "err.log")
//if commonUtils.IsWin() {
// logPathInfo = filepath.Join(WinFileSchema, logPathInfo)
// logPathErr = filepath.Join(WinFileSchema, logPathErr)
//}
//config.OutputPaths = []string{"stdout", logPathInfo}
//config.ErrorOutputPaths = []string{"stderr", logPathErr}
return return
} }
...@@ -170,3 +172,24 @@ func newWinFileSink(u *url.URL) (zap.Sink, error) { ...@@ -170,3 +172,24 @@ func newWinFileSink(u *url.URL) (zap.Sink, error) {
} }
return os.OpenFile(name, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666) return os.OpenFile(name, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
} }
func zapCore(c zapcore.Core) zapcore.Core {
logPathInfo := filepath.Join(CONFIG.Zap.Director, "ztf.log")
w := zapcore.AddSync(&lumberjack.Logger{
Filename: logPathInfo,
LocalTime: true,
MaxSize: 300, // M
MaxAge: 30, // days
MaxBackups: 30,
})
core := zapcore.NewCore(
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
w,
zap.DebugLevel,
)
cores := zapcore.NewTee(c, core)
return cores
}
...@@ -14,15 +14,15 @@ import ( ...@@ -14,15 +14,15 @@ import (
) )
func Get(url string) (ret []byte, err error) { func Get(url string) (ret []byte, err error) {
if commConsts.Verbose { if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof("===DEBUG=== request: %s", url) logUtils.Infof("===DEBUG=== request: %s", url)
} }
client := &http.Client{} client := &http.Client{}
req, err := http.NewRequest("GET", url, nil) req, err := http.NewRequest("GET", url, nil)
if err != nil { if err != nil {
if commConsts.Verbose { if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof(color.RedString("get request failed, error: %s.", err.Error())) logUtils.Infof(color.RedString("get request failed, error: %s.", err.Error()))
} }
return return
...@@ -34,7 +34,7 @@ func Get(url string) (ret []byte, err error) { ...@@ -34,7 +34,7 @@ func Get(url string) (ret []byte, err error) {
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { if err != nil {
if commConsts.Verbose { if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof(color.RedString("get request failed, error: %s.", err.Error())) logUtils.Infof(color.RedString("get request failed, error: %s.", err.Error()))
} }
return return
...@@ -42,7 +42,7 @@ func Get(url string) (ret []byte, err error) { ...@@ -42,7 +42,7 @@ func Get(url string) (ret []byte, err error) {
defer resp.Body.Close() defer resp.Body.Close()
if !IsSuccessCode(resp.StatusCode) { if !IsSuccessCode(resp.StatusCode) {
if commConsts.Verbose { if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof(color.RedString("read response failed, StatusCode: %d.", resp.StatusCode)) logUtils.Infof(color.RedString("read response failed, StatusCode: %d.", resp.StatusCode))
} }
err = errors.New(resp.Status) err = errors.New(resp.Status)
...@@ -50,12 +50,12 @@ func Get(url string) (ret []byte, err error) { ...@@ -50,12 +50,12 @@ func Get(url string) (ret []byte, err error) {
} }
ret, err = ioutil.ReadAll(resp.Body) ret, err = ioutil.ReadAll(resp.Body)
if commConsts.Verbose { if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof("===DEBUG=== response: %s", logUtils.ConvertUnicode(ret)) logUtils.Infof("===DEBUG=== response: %s", logUtils.ConvertUnicode(ret))
} }
if err != nil { if err != nil {
if commConsts.Verbose { if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof(color.RedString("read response failed, error ", err.Error())) logUtils.Infof(color.RedString("read response failed, error ", err.Error()))
} }
return return
...@@ -86,19 +86,19 @@ func Put(url string, data interface{}) (ret []byte, err error) { ...@@ -86,19 +86,19 @@ func Put(url string, data interface{}) (ret []byte, err error) {
} }
func PostOrPut(url string, method string, data interface{}) (ret []byte, err error) { func PostOrPut(url string, method string, data interface{}) (ret []byte, err error) {
if commConsts.Verbose { if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof("===DEBUG=== request: %s", url) logUtils.Infof("===DEBUG=== request: %s", url)
} }
client := &http.Client{} client := &http.Client{}
dataBytes, err := json.Marshal(data) dataBytes, err := json.Marshal(data)
if commConsts.Verbose { if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof("===DEBUG=== data: %s", string(dataBytes)) logUtils.Infof("===DEBUG=== data: %s", string(dataBytes))
} }
if err != nil { if err != nil {
if commConsts.Verbose { if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof(color.RedString("marshal request failed, error: %s.", err.Error())) logUtils.Infof(color.RedString("marshal request failed, error: %s.", err.Error()))
} }
return return
...@@ -108,7 +108,7 @@ func PostOrPut(url string, method string, data interface{}) (ret []byte, err err ...@@ -108,7 +108,7 @@ func PostOrPut(url string, method string, data interface{}) (ret []byte, err err
req, err := http.NewRequest(method, url, strings.NewReader(dataStr)) req, err := http.NewRequest(method, url, strings.NewReader(dataStr))
if err != nil { if err != nil {
if commConsts.Verbose { if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof(color.RedString("post request failed, error: %s.", err.Error())) logUtils.Infof(color.RedString("post request failed, error: %s.", err.Error()))
} }
return return
...@@ -122,14 +122,14 @@ func PostOrPut(url string, method string, data interface{}) (ret []byte, err err ...@@ -122,14 +122,14 @@ func PostOrPut(url string, method string, data interface{}) (ret []byte, err err
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { if err != nil {
if commConsts.Verbose { if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof(color.RedString("post request failed, error: %s.", err.Error())) logUtils.Infof(color.RedString("post request failed, error: %s.", err.Error()))
} }
return return
} }
if !IsSuccessCode(resp.StatusCode) { if !IsSuccessCode(resp.StatusCode) {
if commConsts.Verbose { if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof(color.RedString("post request return '%s'.", resp.Status)) logUtils.Infof(color.RedString("post request return '%s'.", resp.Status))
} }
err = errors.New(resp.Status) err = errors.New(resp.Status)
...@@ -139,12 +139,12 @@ func PostOrPut(url string, method string, data interface{}) (ret []byte, err err ...@@ -139,12 +139,12 @@ func PostOrPut(url string, method string, data interface{}) (ret []byte, err err
ret, err = ioutil.ReadAll(resp.Body) ret, err = ioutil.ReadAll(resp.Body)
defer resp.Body.Close() defer resp.Body.Close()
if commConsts.Verbose { if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof("===DEBUG=== response: %s", logUtils.ConvertUnicode(ret)) logUtils.Infof("===DEBUG=== response: %s", logUtils.ConvertUnicode(ret))
} }
if err != nil { if err != nil {
if commConsts.Verbose { if commConsts.Verbose || commConsts.ExecFrom == commConsts.FromClient {
logUtils.Infof(color.RedString("read response failed, error: %s.", err.Error())) logUtils.Infof(color.RedString("read response failed, error: %s.", err.Error()))
} }
return return
......
...@@ -67,15 +67,6 @@ func ExecFilef(str string, args ...interface{}) { ...@@ -67,15 +67,6 @@ func ExecFilef(str string, args ...interface{}) {
func ExecResult(str string) { func ExecResult(str string) {
LoggerExecResult.Info(str) LoggerExecResult.Info(str)
} }
func ExecResultf(str string, args ...interface{}) {
msg := fmt.Sprintf(str, args...)
LoggerExecResult.Info(msg)
}
func PrintUnicode(str []byte) {
msg := ConvertUnicode(str)
LoggerStandard.Info(msg)
}
func ConvertUnicode(str []byte) string { func ConvertUnicode(str []byte) string {
var a interface{} var a interface{}
...@@ -111,17 +102,6 @@ func GetWholeLine(msg string, char string) string { ...@@ -111,17 +102,6 @@ func GetWholeLine(msg string, char string) string {
return fmt.Sprintf("%s %s %s", preFixStr, msg, postFixStr) return fmt.Sprintf("%s %s %s", preFixStr, msg, postFixStr)
} }
func PrintToCmd(msg string, attr color.Attribute) {
output := color.Output
if attr == -1 {
fmt.Fprint(output, msg+"\n")
} else {
clr := color.New(attr)
clr.Fprint(output, msg+"\n")
}
}
func PrintVersion(appVersion, buildTime, goVersion, gitHash string) { func PrintVersion(appVersion, buildTime, goVersion, gitHash string) {
fmt.Printf("%s \n", appVersion) fmt.Printf("%s \n", appVersion)
fmt.Printf("Build TimeStamp: %s \n", buildTime) fmt.Printf("Build TimeStamp: %s \n", buildTime)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册