Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
c7ca118c
Commit
c7ca118c
authored
Apr 10, 2015
by
Dawn Chen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6682 from thockin/spew-keys-in-hash
Make DeepHashObject use SpewKeys
parents
1db18948
c989f30a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
26 deletions
+10
-26
hash.go
pkg/util/hash.go
+6
-1
hash_test.go
pkg/util/hash_test.go
+4
-25
No files found.
pkg/util/hash.go
View file @
c7ca118c
...
...
@@ -27,6 +27,11 @@ import (
// 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
:=
spew
.
ConfigState
{
Indent
:
" "
,
SortKeys
:
true
,
DisableMethods
:
true
,
SpewKeys
:
true
,
}
printer
.
Fprintf
(
hasher
,
"%#v"
,
objectToWrite
)
}
pkg/util/hash_test.go
View file @
c7ca118c
...
...
@@ -44,31 +44,6 @@ func (c C) String() string {
}
func
TestDeepHashObject
(
t
*
testing
.
T
)
{
// These types are known to fail object hashing because of how spew implements map keys.
// http://github.com/davecgh/go-spew/issues/30
failureCases
:=
[]
func
()
interface
{}{
func
()
interface
{}
{
return
map
[
A
]
bool
{
A
{
8675309
,
"Jenny"
}
:
true
,
A
{
9765683
,
"!Jenny"
}
:
false
}
},
func
()
interface
{}
{
return
map
[
C
]
bool
{
C
{
8675309
,
"Jenny"
}
:
true
,
C
{
9765683
,
"!Jenny"
}
:
false
}
},
func
()
interface
{}
{
return
map
[
*
A
]
bool
{
&
A
{
8675309
,
"Jenny"
}
:
true
,
&
A
{
9765683
,
"!Jenny"
}
:
false
}
},
func
()
interface
{}
{
return
map
[
*
C
]
bool
{
&
C
{
8675309
,
"Jenny"
}
:
true
,
&
C
{
9765683
,
"!Jenny"
}
:
false
}
},
}
for
_
,
tc
:=
range
failureCases
{
hasher
:=
adler32
.
New
()
DeepHashObject
(
hasher
,
tc
())
first
:=
hasher
.
Sum32
()
alwaysSame
:=
false
for
i
:=
0
;
i
<
100
;
i
++
{
DeepHashObject
(
hasher
,
tc
())
if
hasher
.
Sum32
()
!=
first
{
alwaysSame
=
false
break
}
}
if
alwaysSame
{
t
.
Errorf
(
"expected failure for %q"
,
toString
(
tc
()))
}
}
successCases
:=
[]
func
()
interface
{}{
func
()
interface
{}
{
return
8675309
},
func
()
interface
{}
{
return
"Jenny, I got your number"
},
...
...
@@ -81,6 +56,10 @@ func TestDeepHashObject(t *testing.T) {
func
()
interface
{}
{
return
B
{[]
int
{
8
,
6
,
7
},
map
[
string
]
bool
{
"5"
:
true
,
"3"
:
true
,
"0"
:
true
,
"9"
:
true
}}
},
func
()
interface
{}
{
return
map
[
A
]
bool
{
A
{
8675309
,
"Jenny"
}
:
true
,
A
{
9765683
,
"!Jenny"
}
:
false
}
},
func
()
interface
{}
{
return
map
[
C
]
bool
{
C
{
8675309
,
"Jenny"
}
:
true
,
C
{
9765683
,
"!Jenny"
}
:
false
}
},
func
()
interface
{}
{
return
map
[
*
A
]
bool
{
&
A
{
8675309
,
"Jenny"
}
:
true
,
&
A
{
9765683
,
"!Jenny"
}
:
false
}
},
func
()
interface
{}
{
return
map
[
*
C
]
bool
{
&
C
{
8675309
,
"Jenny"
}
:
true
,
&
C
{
9765683
,
"!Jenny"
}
:
false
}
},
}
for
_
,
tc
:=
range
successCases
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment