From 9ccceac5e8e5811aff95e3147e3c057d1505037a Mon Sep 17 00:00:00 2001 From: Dai Zuozhuo Date: Fri, 21 Aug 2015 15:25:56 +0800 Subject: [PATCH] sort jsonpath_test results --- pkg/util/jsonpath/jsonpath_test.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/util/jsonpath/jsonpath_test.go b/pkg/util/jsonpath/jsonpath_test.go index 86384ac58675e..fa181b346568c 100644 --- a/pkg/util/jsonpath/jsonpath_test.go +++ b/pkg/util/jsonpath/jsonpath_test.go @@ -20,6 +20,9 @@ import ( "bytes" "encoding/json" "fmt" + "reflect" + "sort" + "strings" "testing" ) @@ -43,7 +46,12 @@ func testJSONPath(tests []jsonpathTest, t *testing.T) { t.Errorf("in %s, execute error %v", test.name, err) } out := buf.String() - if out != test.expect { + //since map is itereated in random order, we need to sort the results. + sortedOut := strings.Fields(out) + sort.Strings(sortedOut) + sortedExpect := strings.Fields(test.expect) + sort.Strings(sortedExpect) + if !reflect.DeepEqual(sortedOut, sortedExpect) { t.Errorf(`in %s, expect to get "%s", got "%s"`, test.name, test.expect, out) } }