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

Latest commit

 

History

History
110 lines (93 loc) · 2.25 KB

templating.md

File metadata and controls

110 lines (93 loc) · 2.25 KB

Output templating

Go template syntax

See Go's text/template package documentation

Report structure reference for usage in templates

{
    Benchmark {
        Length  int
        Success int
        Fail    int
        Duration time.Duration
        Records []{
            Time   time.Duration
            Code   int          
            Bytes  int          
            Error  string       
            Events []{
                Name string
                Time time.Duration
            }
        }
    }

    Metadata {
        Config {
            Request {
                Method string
                URL    *url.URL
                Header http.Header
                Body   Body
            }
            Runner {
                Requests       int
                Concurrency    int
                Interval       time.Duration
                RequestTimeout time.Duration
                GlobalTimeout  time.Duration
            }
            Output {
                Out      []string
                Silent   bool
                Template string
            }
        }

        FinishedAt time.Time
    }
}

Additionnal template functions

  • stats:

    • {{ stats.Min }}: Minimum recorded request time
    • {{ stats.Max }}: Maximum recorded request time
    • {{ stats.Mean }}: Mean request time
  • fail:

    • {{ fail }}: Fails the test and exit 1 (better used in a condition!)
    • {{ fail "Too long!" }}: Same with error message

Some examples

  • Custom summary

    template: |
      {{ .Benchmark.Length }}/{{ .Metadata.Config.Runner.Requests }} requests
      {{ .Benchmark.Fail }} errors
      ✔︎ Done in {{ .Benchmark.Duration.Milliseconds }}ms.
    100/100 requests
    0 errors
    ✔︎ Done in 2034ms.
  • Display only the average request time

    template: '{{ stats.Mean }}'
    237ms
  • Fail the test if any request exceeds 200ms

    template: |
      {{- if ge stats.Max.Milliseconds 200 -}}
          {{ fail "TOO SLOW" }}
      {{- else -}}
          OK
      {{- end -}}

    if max >= 200ms:

    test failed: TOO SLOW
    exit status 1

    else:

    OK