From 6e2eb1944146763e7198337f71a83478e2193384 Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Fri, 15 Nov 2019 14:58:55 +0700 Subject: [PATCH] add test to make sure hashstruct is sorting the map and struct keys --- hash/structhash/structhash_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/hash/structhash/structhash_test.go b/hash/structhash/structhash_test.go index b7c86a513..9aa2f0bdf 100644 --- a/hash/structhash/structhash_test.go +++ b/hash/structhash/structhash_test.go @@ -41,6 +41,7 @@ func TestDump(t *testing.T) { {map[int]int{}, "()"}, {map[int]int{0: 0}, "(0:0)"}, {map[int]int{0: 0, 1: 1}, "(0:0,1:1)"}, + {map[int]int{1: 1, 0: 0}, "(0:0,1:1)"}, {[]int(nil), "[]nil"}, {[]*int{nil}, "[nil]"}, {[]int{}, "[]"}, @@ -84,6 +85,26 @@ func TestDump(t *testing.T) { }, "{a:{b:(\"c\":1)}}", }, + { + struct { + a interface{} `hash:"name:a"` + }{ + struct { + c map[string]int `hash:"name:c"` + b map[string]int `hash:"name:b"` + }{ + c: map[string]int{ + "100": 1, + "1": 1, + }, + b: map[string]int{ + "100": 1, + "1": 1, + }, + }, + }, + "{a:{b:(\"1\":1,\"100\":1),c:(\"1\":1,\"100\":1)}}", + }, // NOTE: structhash will allow to process all interface types. // gogo/protobuf is not able to set tags for directly oneof interface. // see: https://github.com/gogo/protobuf/issues/623