mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-06 00:09:37 +08:00
feat: record execution data for report #25
This commit is contained in:
@@ -16,7 +16,7 @@ var Assertions = map[string]func(t assert.TestingT, expected interface{}, actual
|
||||
"greater_or_equals": assert.GreaterOrEqual,
|
||||
"less_or_equals": assert.LessOrEqual,
|
||||
"not_equal": assert.NotEqual,
|
||||
"contained_by": assert.Contains,
|
||||
"contained_by": assert.Contains,
|
||||
"regex_match": assert.Regexp,
|
||||
"type_match": assert.IsType,
|
||||
// custom assertions
|
||||
@@ -28,7 +28,7 @@ var Assertions = map[string]func(t assert.TestingT, expected interface{}, actual
|
||||
"length_less_or_equals": LessOrEqualsLength,
|
||||
"length_greater_than": GreaterThanLength,
|
||||
"length_greater_or_equals": GreaterOrEqualsLength,
|
||||
"contains": Contains,
|
||||
"contains": Contains,
|
||||
"string_equals": EqualString,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package builtin
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"encoding/csv"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"math/rand"
|
||||
@@ -11,6 +13,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
@@ -19,7 +23,7 @@ var Functions = map[string]interface{}{
|
||||
"sleep": sleep, // call with one argument
|
||||
"gen_random_string": genRandomString, // call with one argument
|
||||
"max": math.Max, // call with two arguments
|
||||
"md5": MD5, // call with one argument
|
||||
"md5": MD5, // call with one argument
|
||||
"parameterize": loadFromCSV,
|
||||
"P": loadFromCSV,
|
||||
}
|
||||
@@ -82,3 +86,46 @@ func loadFromCSV(path string) []map[string]interface{} {
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func Dump2JSON(data interface{}, path string) error {
|
||||
path, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("convert absolute path failed")
|
||||
return err
|
||||
}
|
||||
log.Info().Str("path", path).Msg("dump data to json")
|
||||
file, _ := json.MarshalIndent(data, "", " ")
|
||||
err = ioutil.WriteFile(path, file, 0644)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("dump json path failed")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Dump2YAML(data interface{}, path string) error {
|
||||
path, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("convert absolute path failed")
|
||||
return err
|
||||
}
|
||||
log.Info().Str("path", path).Msg("dump data to yaml")
|
||||
|
||||
// init yaml encoder
|
||||
buffer := new(bytes.Buffer)
|
||||
encoder := yaml.NewEncoder(buffer)
|
||||
encoder.SetIndent(4)
|
||||
|
||||
// encode
|
||||
err = encoder.Encode(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(path, buffer.Bytes(), 0644)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("dump yaml path failed")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user