-
Notifications
You must be signed in to change notification settings - Fork 1
/
json.go
40 lines (32 loc) · 922 Bytes
/
json.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
package test_tools
import (
"fmt"
"sort"
"testing"
"github.com/stretchr/testify/assert"
)
type Json map[string]interface{}
type JsonList []Json
func (j Json) keys() []string {
keys := make([]string, 0)
for key := range j {
keys = append(keys, key)
}
return keys
}
func (actual Json) Equal(t *testing.T, expected Json) {
expectedKeys := sort.StringSlice(expected.keys())
expectedKeys.Sort()
actualKeys := sort.StringSlice(actual.keys())
actualKeys.Sort()
assert.Equal(t, expectedKeys, actualKeys)
for _, key := range expectedKeys {
assert.Equal(t, expected[key], actual[key], fmt.Sprintf("Comparing key %s", key))
}
}
func (actualList JsonList) Equal(t *testing.T, expectedList JsonList) {
assert.Equal(t, len(expectedList), len(actualList))
for i, expected := range expectedList {
actualList[i].Equal(t, expected)
}
}