-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils_test.go
More file actions
42 lines (36 loc) · 749 Bytes
/
Copy pathutils_test.go
File metadata and controls
42 lines (36 loc) · 749 Bytes
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
package jsonapi_test
import (
"encoding/json"
"fmt"
"reflect"
"strings"
"testing"
)
func catchPanic(t *testing.T, typ, method string) {
if r := recover(); r != nil {
t.Errorf("%s.%s() should not panic when %s is nil", typ, method, typ)
}
}
func compareJSON(a, b string) error {
var ar, br interface{}
err := json.Unmarshal([]byte(a), &ar)
if err != nil {
return err
}
err = json.Unmarshal([]byte(b), &br)
if err != nil {
return err
}
if !reflect.DeepEqual(ar, br) {
a = stripJSON(a)
b = stripJSON(b)
return fmt.Errorf("\n%s\n!=\n%s", a, b)
}
return nil
}
func stripJSON(s string) string {
s = strings.Replace(s, "\n", "", -1)
s = strings.Replace(s, " ", "", -1)
s = strings.Replace(s, "\t", "", -1)
return s
}