mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
feat: generate html reports for API testing #74
This commit is contained in:
@@ -10,7 +10,6 @@ import (
|
||||
"math"
|
||||
"math/rand"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -131,33 +130,15 @@ func Dump2YAML(data interface{}, path string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func formatValue(raw interface{}) interface{} {
|
||||
rawValue := reflect.ValueOf(raw)
|
||||
switch rawValue.Kind() {
|
||||
case reflect.Map:
|
||||
m := make(map[string]interface{})
|
||||
for key, value := range rawValue.Interface().(map[string]interface{}) {
|
||||
fmtValue, ok := value.(string)
|
||||
if !ok {
|
||||
b, _ := json.MarshalIndent(&value, "", " ")
|
||||
fmtValue = string(b)
|
||||
}
|
||||
m[key] = fmtValue
|
||||
}
|
||||
return m
|
||||
case reflect.Slice:
|
||||
b, _ := json.MarshalIndent(&raw, "", " ")
|
||||
return string(b)
|
||||
default:
|
||||
return raw
|
||||
}
|
||||
}
|
||||
|
||||
func FormatResponse(raw interface{}) interface{} {
|
||||
formattedResponse := make(map[string]interface{})
|
||||
for key, value := range raw.(map[string]interface{}) {
|
||||
// convert value to json
|
||||
formattedResponse[key] = formatValue(value)
|
||||
if key == "body" {
|
||||
b, _ := json.MarshalIndent(&value, "", " ")
|
||||
value = string(b)
|
||||
}
|
||||
formattedResponse[key] = value
|
||||
}
|
||||
return formattedResponse
|
||||
}
|
||||
|
||||
@@ -273,10 +273,6 @@
|
||||
{{- range $k, $v := $value}}
|
||||
<pre>{{$k}}: {{$v}}</pre>
|
||||
{{- end -}}
|
||||
{{- else if eq $key "body" }}
|
||||
{{- range $k, $v := $value }}
|
||||
<pre>{{$k}}: {{$v}}</pre>
|
||||
{{- end -}}
|
||||
{{- else if eq $key "cookies" }}
|
||||
{{- range $k, $v := $value }}
|
||||
<pre>{{$k}}: {{$v}}</pre>
|
||||
|
||||
Reference in New Issue
Block a user