提交 3acd6fef 编写于 作者: 陈琦

fix issue of load res from file path

上级 babe2895
Version = 1.8
Version = 1.8
Language = zh
......@@ -268,7 +268,7 @@ func CreateValuesFromYaml(field *model.DefField, yamlFile, stepStr string, repea
configDir := vari.ConfigFileDir
res := vari.Res
configFile := fileUtils.ComputerReferFilePath(yamlFile)
configFile := fileUtils.ComputerReferFilePath(yamlFile, nil)
fieldsToExport := make([]string, 0) // set to empty to use all fields
rows, colIsNumArr, _ := GenerateOnTopLevel("", configFile, &fieldsToExport)
if field.Rand {
......
......@@ -145,9 +145,9 @@ func getResFromInstances(insts model.ResInstances) (groupedValue map[string][]st
}
// gen values
field := convertInstantToField(insts, inst)
fieldFromInsts := convertInstantToField(insts, inst)
group := inst.Instance
groupedValue[group] = GenerateForField(&field, false)
groupedValue[group] = GenerateForField(&fieldFromInsts, false)
}
return groupedValue
......@@ -251,6 +251,7 @@ func convertInstantToField(insts model.ResInstances, inst model.ResInstancesItem
copier.Copy(&child, inst)
field.Fields = append(field.Fields, child)
field.FileDir = insts.FileDir
return field
}
......
......@@ -16,6 +16,7 @@ import (
func CreateFieldValuesFromText(field *model.DefField, fieldValue *model.FieldWithValues) {
ranges := strings.Split(strings.TrimSpace(field.Range), ",")
for _, rang := range ranges {
rang = strings.TrimSpace(rang)
repeat, repeatTag, rangWithoutRepeat := ParseRepeat(rang)
......@@ -30,7 +31,7 @@ func CreateFieldValuesFromText(field *model.DefField, fieldValue *model.FieldWit
// read from file
list := make([]string, 0)
realPath := fileUtils.ComputerReferFilePath(file)
realPath := fileUtils.ComputerReferFilePath(file, field)
content, err := ioutil.ReadFile(realPath)
if err != nil {
logUtils.PrintTo(i118Utils.I118Prt.Sprintf("fail_to_read_file", file+" - "+realPath))
......
......@@ -2,6 +2,7 @@ package fileUtils
import (
"github.com/easysoft/zendata/res"
"github.com/easysoft/zendata/src/model"
commonUtils "github.com/easysoft/zendata/src/utils/common"
constant "github.com/easysoft/zendata/src/utils/const"
i118Utils "github.com/easysoft/zendata/src/utils/i118"
......@@ -312,9 +313,14 @@ func ConvertResExcelPath(from, dir string) (ret, sheet string) {
return
}
func ComputerReferFilePath(file string) (resPath string) {
func ComputerReferFilePath(file string, field *model.DefField) (resPath string) {
resPath = file
if filepath.IsAbs(resPath) && FileExist(resPath) {
if IsAbsPath(resPath) && FileExist(resPath) {
return
}
resPath = field.FileDir + file
if FileExist(resPath) {
return
}
......@@ -328,11 +334,11 @@ func ComputerReferFilePath(file string) (resPath string) {
return
}
resPath = vari.ZdPath + constant.ResDirYaml + constant.PthSep + file
resPath = vari.ZdPath + constant.ResDirUsers + constant.PthSep + file
if FileExist(resPath) {
return
}
resPath = vari.ZdPath + constant.ResDirUsers + constant.PthSep + file
resPath = vari.ZdPath + constant.ResDirYaml + constant.PthSep + file
if FileExist(resPath) {
return
}
......
......@@ -204,7 +204,7 @@ func main() {
func toGen() {
tmStart := time.Now()
if vari.Verbose {
logUtils.PrintTo(fmt.Sprintf("Start at %s", tmStart.Format("2006-01-02 15:04:05")))
logUtils.PrintTo(fmt.Sprintf("Start at %s.", tmStart.Format("2006-01-02 15:04:05")))
}
if vari.RunMode == constant.RunModeServer {
......@@ -256,10 +256,10 @@ func toGen() {
tmEnd := time.Now()
if vari.Verbose {
logUtils.PrintTo(fmt.Sprintf("End at %s", tmEnd.Format("2006-01-02 15:04:05")))
logUtils.PrintTo(fmt.Sprintf("End at %s.", tmEnd.Format("2006-01-02 15:04:05")))
dur := tmEnd.Unix() - tmStart.Unix()
logUtils.PrintTo(fmt.Sprintf("Duriation %d", dur))
logUtils.PrintTo(fmt.Sprintf("Duriation %d sec.", dur))
}
}
......
......@@ -2,45 +2,7 @@ title: test
desc: 描述
version: 1.0
fields:
# 127.0.0.1 - - [10/Jan/2021:14:02:05 +0800] "GET /index.php HTTP/1.1" 200 1404 "-" "<AGENT>"
# - field: apache log
# from: log.apache.access.v1.yaml
# use: log
- field: host
from: ip.v2.yaml
use: ipC{10},ipB{10},ipA{10}
postfix: " - - "
- field: date time
range: "(-1W):60" # 支持当前时间的运算,Y、M、D、W、h、m、s分别对应年、月、日、周、时、分、秒。
type: timestamp # 月份、星期几的长、短格式,可用January、Jan、Monday、Mon字符串。
format: "DD/Jan/YYYY:hh:mm:ss"
prefix: "["
postfix: " +0800] "
- field: request uri
range: yaml/log/uri.txt:R
prefix: '"GET /'
postfix: ' HTTP/1.1" '
- field: response code
range: 200{50},404,500
postfix: " "
rand: true
- field: request size
range: 100-1900:R{3},10000-99999{10}
postfix: " "
rand: true
- field: request-size
range: []{8},["-"] # 空或-
postfix: " "
rand: true
- field: agent
range: yaml/log/agent.txt:R
prefix: '"'
postfix: '"'
\ No newline at end of file
- field: apache log
from: log.apache.access.v1.yaml
use: log
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册