From 9ed6c95e8e818f4f49a865e0ab70a95a2f2beb2f Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Mon, 23 Mar 2015 21:25:51 -0700 Subject: [PATCH] Reset hash state between runs. --- pkg/util/hash.go | 1 + pkg/util/hash_test.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/pkg/util/hash.go b/pkg/util/hash.go index c4dbe6e345..1d706b7def 100644 --- a/pkg/util/hash.go +++ b/pkg/util/hash.go @@ -26,6 +26,7 @@ import ( // which follows pointers and prints actual values of the nested objects // ensuring the hash does not change when a pointer changes. func DeepHashObject(hasher hash.Hash, objectToWrite interface{}) { + hasher.Reset() printer := spew.ConfigState{Indent: " ", SortKeys: true} printer.Fprintf(hasher, "%#v", objectToWrite) } diff --git a/pkg/util/hash_test.go b/pkg/util/hash_test.go index 553e720bcb..db766811ce 100644 --- a/pkg/util/hash_test.go +++ b/pkg/util/hash_test.go @@ -49,12 +49,18 @@ func TestDeepObjectPointer(t *testing.T) { // Act DeepHashObject(hasher1, myUni1) hash1 := hasher1.Sum32() + DeepHashObject(hasher1, myUni1) + hash1a := hasher1.Sum32() DeepHashObject(hasher2, myUni2) hash2 := hasher2.Sum32() DeepHashObject(hasher3, myUni3) hash3 := hasher3.Sum32() // Assert + if hash1 != hash1a { + t.Errorf("repeated hash of the same object produced different results: %d vs %d", hash1, hash1a) + } + if hash1 == hash2 { t.Errorf("hash1 (%d) and hash2(%d) must be different because they have different values for wheel size", hash1, hash2) }