From 1310fcfc0bfac9c8914aa5b5075f5e91247a25a3 Mon Sep 17 00:00:00 2001 From: Wlad Meixner Date: Tue, 12 Feb 2019 01:26:50 +0100 Subject: [PATCH] update comments --- utils/test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/utils/test.go b/utils/test.go index 9ce63b8..59a030b 100644 --- a/utils/test.go +++ b/utils/test.go @@ -9,6 +9,7 @@ import ( "github.com/sergi/go-diff/diffmatchpatch" ) +// CompareJSONDecode decodes a JSON string into a provided interface and then back to a json string. If the output json string does not match the compact version of the input string a error is returned func CompareJSONDecode(j string, v interface{}) error { bytes, errCompact := CompactJSON(j) if errCompact != nil { @@ -26,6 +27,7 @@ func CompareJSONDecode(j string, v interface{}) error { return DiffStrings(old, new) } +// CompareStructToJSON compares Marshaled interface to a JSON string and returns an error if they do not match func CompareStructToJSON(v interface{}, j string) error { // Remove all extra spaces from json string bytes, errCompact := CompactJSON(j) @@ -43,6 +45,7 @@ func CompareStructToJSON(v interface{}, j string) error { return DiffStrings(old, new) } +// DiffStrings prints a nice compare between strings. Error is returned if strings are not equal func DiffStrings(s1, s2 string) error { if s1 != s2 { fmt.Println("String do not match!") @@ -62,6 +65,7 @@ func DiffStrings(s1, s2 string) error { return nil } +// CompactJSON removes all whitespaces between json keys and values that is not required func CompactJSON(j string) ([]byte, error) { buffer := new(bytes.Buffer) @@ -74,3 +78,5 @@ func CompactJSON(j string) ([]byte, error) { return bytes, nil } + +// BridgeFromEnv creates a bridge from the config data stored in env. This is primarily designed for automated tests