/
tests.go
52 lines (42 loc) · 1 KB
/
tests.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Package tests provides the generic support all tests require.
package tests
import (
"bytes"
"encoding/json"
"os"
"testing"
)
// TraceID provides a base trace id for tests.
var TraceID = "Test"
// Success and failure markers.
var (
Success = "\u2713"
Failed = "\u2717"
)
// Logdash is the central buffer where all logs are stored.
var Logdash bytes.Buffer
// ResetLog resets the contents of Logdash.
func ResetLog() {
Logdash.Reset()
}
// DisplayLog writes the Logdash data to standand out, if testing in verbose mode
// was turned on.
func DisplayLog() {
if !testing.Verbose() {
return
}
Logdash.WriteTo(os.Stdout)
}
// IndentJSON takes a JSON payload as a string and re-indents it to make
// comparing expected strings to tests strings during testing.
func IndentJSON(j string) string {
var indented interface{}
if err := json.Unmarshal([]byte(j), &indented); err != nil {
return ""
}
data, err := json.MarshalIndent(indented, "", " ")
if err != nil {
return ""
}
return string(data)
}