mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 07:26:55 +08:00
change: replace logs
This commit is contained in:
+1
-1
@@ -70,7 +70,7 @@ func loadFromJSON(path string) (*TCase, error) {
|
|||||||
log.Errorf("convert absolute path error: %v, path: %v", err, path)
|
log.Errorf("convert absolute path error: %v, path: %v", err, path)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
log.Infof("load testcase from json path: %s", path)
|
log.WithField("path", path).Info("load json testcase")
|
||||||
|
|
||||||
file, err := ioutil.ReadFile(path)
|
file, err := ioutil.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+5
-1
@@ -120,7 +120,11 @@ func (h *HAR) prepareTestSteps() ([]*hrp.TStep, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *HAR) prepareTestStep(entry *Entry) (*hrp.TStep, error) {
|
func (h *HAR) prepareTestStep(entry *Entry) (*hrp.TStep, error) {
|
||||||
log.Infof("[prepareTestStep] %v %v", entry.Request.Method, entry.Request.URL)
|
log.WithFields(log.Fields{
|
||||||
|
"method": entry.Request.Method,
|
||||||
|
"url": entry.Request.URL,
|
||||||
|
}).Info("convert teststep")
|
||||||
|
|
||||||
tStep := &TStep{
|
tStep := &TStep{
|
||||||
TStep: hrp.TStep{
|
TStep: hrp.TStep{
|
||||||
Request: &hrp.TRequest{},
|
Request: &hrp.TRequest{},
|
||||||
|
|||||||
@@ -291,10 +291,7 @@ func callFunc(funcName string, arguments ...interface{}) (interface{}, error) {
|
|||||||
argumentsValue[index] = argumentValue.Convert(expectArgumentType)
|
argumentsValue[index] = argumentValue.Convert(expectArgumentType)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("[callFunction] func: %v, input arguments: %v", funcName, arguments)
|
|
||||||
resultValues := funcValue.Call(argumentsValue)
|
resultValues := funcValue.Call(argumentsValue)
|
||||||
log.Infof("[callFunction] output values: %v", resultValues)
|
|
||||||
|
|
||||||
if len(resultValues) > 1 {
|
if len(resultValues) > 1 {
|
||||||
// function should return at most one value
|
// function should return at most one value
|
||||||
err := fmt.Errorf("function %s should return at most one value", funcName)
|
err := fmt.Errorf("function %s should return at most one value", funcName)
|
||||||
@@ -310,7 +307,11 @@ func callFunc(funcName string, arguments ...interface{}) (interface{}, error) {
|
|||||||
// return one value
|
// return one value
|
||||||
// convert reflect.Value to interface{}
|
// convert reflect.Value to interface{}
|
||||||
result := resultValues[0].Interface()
|
result := resultValues[0].Interface()
|
||||||
log.Infof("[callFunction] output result: %+v(%T)", result, result)
|
log.WithFields(log.Fields{
|
||||||
|
"funcName": funcName,
|
||||||
|
"arguments": arguments,
|
||||||
|
"output": result,
|
||||||
|
}).Info("call function")
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-3
@@ -77,8 +77,8 @@ func (v *ResponseObject) Extract(extractors map[string]string) map[string]interf
|
|||||||
extractMapping := make(map[string]interface{})
|
extractMapping := make(map[string]interface{})
|
||||||
for key, value := range extractors {
|
for key, value := range extractors {
|
||||||
extractedValue := v.searchJmespath(value)
|
extractedValue := v.searchJmespath(value)
|
||||||
log.Infof("[extract] %s => %v", value, extractedValue)
|
log.WithField("value", extractedValue).Infof("extract value from %s", value)
|
||||||
log.Infof("[setVariable] %s = %v", key, extractedValue)
|
log.WithField("value", extractedValue).Infof("set variable %s", key)
|
||||||
extractMapping[key] = extractedValue
|
extractMapping[key] = extractedValue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +112,12 @@ func (v *ResponseObject) Validate(validators []TValidator, variablesMapping map[
|
|||||||
|
|
||||||
// do assertion
|
// do assertion
|
||||||
result := assertFunc(v.t, expectValue, checkValue)
|
result := assertFunc(v.t, expectValue, checkValue)
|
||||||
log.Infof("[assert] %s <%s> %v => %v", checkItem, assertMethod, expectValue, result)
|
log.WithFields(log.Fields{
|
||||||
|
"assertMethod": assertMethod,
|
||||||
|
"expectValue": expectValue,
|
||||||
|
"checkValue": checkValue,
|
||||||
|
"result": result,
|
||||||
|
}).Infof("validate %s", checkItem)
|
||||||
if !result {
|
if !result {
|
||||||
v.t.Fail()
|
v.t.Fail()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,11 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
log.SetLevel(log.InfoLevel)
|
||||||
|
log.SetFormatter(&log.TextFormatter{})
|
||||||
|
}
|
||||||
|
|
||||||
// run API test with default configs
|
// run API test with default configs
|
||||||
func Run(t *testing.T, testcases ...ITestCase) error {
|
func Run(t *testing.T, testcases ...ITestCase) error {
|
||||||
return NewRunner().WithTestingT(t).SetDebug(true).Run(testcases...)
|
return NewRunner().WithTestingT(t).SetDebug(true).Run(testcases...)
|
||||||
@@ -29,19 +34,19 @@ type Runner struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) WithTestingT(t *testing.T) *Runner {
|
func (r *Runner) WithTestingT(t *testing.T) *Runner {
|
||||||
log.Infof("[init] WithTestingT: %v", t)
|
log.Info("[init] WithTestingT")
|
||||||
r.t = t
|
r.t = t
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) SetDebug(debug bool) *Runner {
|
func (r *Runner) SetDebug(debug bool) *Runner {
|
||||||
log.Infof("[init] SetDebug: %v", debug)
|
log.WithField("debug", debug).Info("[init] SetDebug")
|
||||||
r.debug = debug
|
r.debug = debug
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) SetProxyUrl(proxyUrl string) *Runner {
|
func (r *Runner) SetProxyUrl(proxyUrl string) *Runner {
|
||||||
log.Infof("[init] SetProxyUrl: %s", proxyUrl)
|
log.WithField("proxyUrl", proxyUrl).Info("[init] SetProxyUrl")
|
||||||
r.client.SetProxyUrl(proxyUrl)
|
r.client.SetProxyUrl(proxyUrl)
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
@@ -67,7 +72,7 @@ func (r *Runner) runCase(testcase *TestCase) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("Start to run testcase: %v", config.Name)
|
log.WithField("testcase", config.Name).Info("run testcase start")
|
||||||
|
|
||||||
extractedVariables := make(map[string]interface{})
|
extractedVariables := make(map[string]interface{})
|
||||||
|
|
||||||
@@ -96,11 +101,12 @@ func (r *Runner) runCase(testcase *TestCase) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.WithField("testcase", config.Name).Info("run testcase end")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) runStep(step IStep, config *TConfig) (stepData *StepData, err error) {
|
func (r *Runner) runStep(step IStep, config *TConfig) (stepData *StepData, err error) {
|
||||||
log.Infof("run step [%v] begin >>>>>>", step.Name())
|
log.WithField("step", step.Name()).Info("run step start")
|
||||||
if tc, ok := step.(*testcaseWithOptionalArgs); ok {
|
if tc, ok := step.(*testcaseWithOptionalArgs); ok {
|
||||||
// run referenced testcase
|
// run referenced testcase
|
||||||
log.Infof("run referenced testcase: %v", tc.step.Name)
|
log.Infof("run referenced testcase: %v", tc.step.Name)
|
||||||
@@ -117,8 +123,11 @@ func (r *Runner) runStep(step IStep, config *TConfig) (stepData *StepData, err e
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Infof("run step [%v] end, success: %v, responseLength: %v <<<<<<\n",
|
log.WithFields(log.Fields{
|
||||||
step.Name(), stepData.Success, stepData.ResponseLength)
|
"step": step.Name(),
|
||||||
|
"success": stepData.Success,
|
||||||
|
"exportVars": stepData.ExportVars,
|
||||||
|
}).Info("run step end")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user