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
481de197
Unverified
Commit
481de197
authored
Mar 20, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Mar 20, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #75156 from smarterclayton/diff_invalid
Handle nil interface inputs to diff.ObjectReflectDiff
parents
8b19a249
fa0fd287
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 @
481de197
...
@@ -448,7 +448,6 @@ staging/src/k8s.io/apimachinery/pkg/test
...
@@ -448,7 +448,6 @@ staging/src/k8s.io/apimachinery/pkg/test
staging/src/k8s.io/apimachinery/pkg/types
staging/src/k8s.io/apimachinery/pkg/types
staging/src/k8s.io/apimachinery/pkg/util/cache
staging/src/k8s.io/apimachinery/pkg/util/cache
staging/src/k8s.io/apimachinery/pkg/util/clock
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/errors
staging/src/k8s.io/apimachinery/pkg/util/framer
staging/src/k8s.io/apimachinery/pkg/util/framer
staging/src/k8s.io/apimachinery/pkg/util/httpstream
staging/src/k8s.io/apimachinery/pkg/util/httpstream
...
...
staging/src/k8s.io/apimachinery/pkg/util/diff/diff.go
View file @
481de197
...
@@ -78,7 +78,20 @@ func ObjectGoPrintDiff(a, b interface{}) string {
...
@@ -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
{
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
)
vA
,
vB
:=
reflect
.
ValueOf
(
a
),
reflect
.
ValueOf
(
b
)
if
vA
.
Type
()
!=
vB
.
Type
()
{
if
vA
.
Type
()
!=
vB
.
Type
()
{
return
fmt
.
Sprintf
(
"type A %T and type B %T do not match"
,
a
,
b
)
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 @
481de197
...
@@ -27,6 +27,20 @@ func TestObjectReflectDiff(t *testing.T) {
...
@@ -27,6 +27,20 @@ func TestObjectReflectDiff(t *testing.T) {
a
,
b
interface
{}
a
,
b
interface
{}
out
string
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"
:
{
"map"
:
{
a
:
map
[
string
]
int
{},
a
:
map
[
string
]
int
{},
b
:
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