Skip to content
This repository has been archived by the owner on Mar 28, 2022. It is now read-only.

Commit

Permalink
feat: generate html reports for API testing #74
Browse files Browse the repository at this point in the history
  • Loading branch information
xucong053 committed Feb 8, 2022
1 parent f85e1aa commit 6aeeab2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
29 changes: 5 additions & 24 deletions internal/builtin/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"math"
"math/rand"
"path/filepath"
"reflect"
"strings"
"time"

Expand Down Expand Up @@ -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
}
4 changes: 0 additions & 4 deletions internal/report/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,6 @@ <h3>Response:</h3>
{{- 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>
Expand Down

0 comments on commit 6aeeab2

Please sign in to comment.