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
fa0fd287
Unverified
Commit
fa0fd287
authored
Mar 07, 2019
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle nil interface inputs to diff.ObjectReflectDiff
Causes a panic today. Add godoc bragging about how ridiculously awesome ObjectReflectDiff is.
parent
ad27abde
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
1 deletion
+27
-1
.golint_failures
hack/.golint_failures
+0
-1
diff.go
staging/src/k8s.io/apimachinery/pkg/util/diff/diff.go
+13
-0
diff_test.go
staging/src/k8s.io/apimachinery/pkg/util/diff/diff_test.go
+14
-0
No files found.
hack/.golint_failures
View file @
fa0fd287
...
...
@@ -446,7 +446,6 @@ staging/src/k8s.io/apimachinery/pkg/test
staging/src/k8s.io/apimachinery/pkg/types
staging/src/k8s.io/apimachinery/pkg/util/cache
staging/src/k8s.io/apimachinery/pkg/util/clock
staging/src/k8s.io/apimachinery/pkg/util/diff
staging/src/k8s.io/apimachinery/pkg/util/errors
staging/src/k8s.io/apimachinery/pkg/util/framer
staging/src/k8s.io/apimachinery/pkg/util/httpstream
...
...
staging/src/k8s.io/apimachinery/pkg/util/diff/diff.go
View file @
fa0fd287
...
...
@@ -78,7 +78,20 @@ func ObjectGoPrintDiff(a, b interface{}) string {
)
}
// ObjectReflectDiff returns a multi-line formatted diff between two objects
// of equal type. If an object with private fields is passed you will
// only see string comparison for those fields. Otherwise this presents the
// most human friendly diff of two structs of equal type in this package.
func
ObjectReflectDiff
(
a
,
b
interface
{})
string
{
if
a
==
nil
&&
b
==
nil
{
return
"<no diffs>"
}
if
a
==
nil
{
return
fmt
.
Sprintf
(
"a is nil and b is not-nil"
)
}
if
b
==
nil
{
return
fmt
.
Sprintf
(
"a is not-nil and b is nil"
)
}
vA
,
vB
:=
reflect
.
ValueOf
(
a
),
reflect
.
ValueOf
(
b
)
if
vA
.
Type
()
!=
vB
.
Type
()
{
return
fmt
.
Sprintf
(
"type A %T and type B %T do not match"
,
a
,
b
)
...
...
staging/src/k8s.io/apimachinery/pkg/util/diff/diff_test.go
View file @
fa0fd287
...
...
@@ -27,6 +27,20 @@ func TestObjectReflectDiff(t *testing.T) {
a
,
b
interface
{}
out
string
}{
"both nil"
:
{
a
:
interface
{}(
nil
),
b
:
interface
{}(
nil
),
},
"a nil"
:
{
a
:
interface
{}(
nil
),
b
:
"test"
,
out
:
"a is nil and b is not-nil"
,
},
"b nil"
:
{
a
:
"test"
,
b
:
interface
{}(
nil
),
out
:
"a is not-nil and b is nil"
,
},
"map"
:
{
a
:
map
[
string
]
int
{},
b
:
map
[
string
]
int
{},
...
...
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