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