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
03792059
Commit
03792059
authored
Mar 03, 2018
by
wrfly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix non-nil ptr struct convert
Signed-off-by:
wrfly
<
mr.wrfly@gmail.com
>
parent
f9f5677b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
1 deletion
+8
-1
convert.go
...k8s.io/apimachinery/pkg/conversion/queryparams/convert.go
+3
-0
convert_test.go
...o/apimachinery/pkg/conversion/queryparams/convert_test.go
+5
-1
No files found.
staging/src/k8s.io/apimachinery/pkg/conversion/queryparams/convert.go
View file @
03792059
...
@@ -174,6 +174,9 @@ func convertStruct(result url.Values, st reflect.Type, sv reflect.Value) {
...
@@ -174,6 +174,9 @@ func convertStruct(result url.Values, st reflect.Type, sv reflect.Value) {
kind
=
ft
.
Kind
()
kind
=
ft
.
Kind
()
if
!
field
.
IsNil
()
{
if
!
field
.
IsNil
()
{
field
=
reflect
.
Indirect
(
field
)
field
=
reflect
.
Indirect
(
field
)
// If the field is non-nil, it should be added to params
// and the omitempty should be overwite to false
omitempty
=
false
}
}
}
}
...
...
staging/src/k8s.io/apimachinery/pkg/conversion/queryparams/convert_test.go
View file @
03792059
...
@@ -70,6 +70,7 @@ type childStructs struct {
...
@@ -70,6 +70,7 @@ type childStructs struct {
Follow
bool
`json:"follow,omitempty"`
Follow
bool
`json:"follow,omitempty"`
Previous
bool
`json:"previous,omitempty"`
Previous
bool
`json:"previous,omitempty"`
SinceSeconds
*
int64
`json:"sinceSeconds,omitempty"`
SinceSeconds
*
int64
`json:"sinceSeconds,omitempty"`
TailLines
*
int64
`json:"tailLines,omitempty"`
SinceTime
*
metav1
.
Time
`json:"sinceTime,omitempty"`
SinceTime
*
metav1
.
Time
`json:"sinceTime,omitempty"`
EmptyTime
*
metav1
.
Time
`json:"emptyTime"`
EmptyTime
*
metav1
.
Time
`json:"emptyTime"`
NonPointerTime
metav1
.
Time
`json:"nonPointerTime"`
NonPointerTime
metav1
.
Time
`json:"nonPointerTime"`
...
@@ -99,6 +100,7 @@ func validateResult(t *testing.T, input interface{}, actual, expected url.Values
...
@@ -99,6 +100,7 @@ func validateResult(t *testing.T, input interface{}, actual, expected url.Values
func
TestConvert
(
t
*
testing
.
T
)
{
func
TestConvert
(
t
*
testing
.
T
)
{
sinceSeconds
:=
int64
(
123
)
sinceSeconds
:=
int64
(
123
)
tailLines
:=
int64
(
0
)
sinceTime
:=
metav1
.
Date
(
2000
,
1
,
1
,
12
,
34
,
56
,
0
,
time
.
UTC
)
sinceTime
:=
metav1
.
Date
(
2000
,
1
,
1
,
12
,
34
,
56
,
0
,
time
.
UTC
)
tests
:=
[]
struct
{
tests
:=
[]
struct
{
...
@@ -182,6 +184,7 @@ func TestConvert(t *testing.T) {
...
@@ -182,6 +184,7 @@ func TestConvert(t *testing.T) {
Follow
:
true
,
Follow
:
true
,
Previous
:
true
,
Previous
:
true
,
SinceSeconds
:
&
sinceSeconds
,
SinceSeconds
:
&
sinceSeconds
,
TailLines
:
nil
,
SinceTime
:
&
sinceTime
,
// test a custom marshaller
SinceTime
:
&
sinceTime
,
// test a custom marshaller
EmptyTime
:
nil
,
// test a nil custom marshaller without omitempty
EmptyTime
:
nil
,
// test a nil custom marshaller without omitempty
NonPointerTime
:
sinceTime
,
NonPointerTime
:
sinceTime
,
...
@@ -194,10 +197,11 @@ func TestConvert(t *testing.T) {
...
@@ -194,10 +197,11 @@ func TestConvert(t *testing.T) {
Follow
:
true
,
Follow
:
true
,
Previous
:
true
,
Previous
:
true
,
SinceSeconds
:
&
sinceSeconds
,
SinceSeconds
:
&
sinceSeconds
,
TailLines
:
&
tailLines
,
SinceTime
:
nil
,
// test a nil custom marshaller with omitempty
SinceTime
:
nil
,
// test a nil custom marshaller with omitempty
NonPointerTime
:
sinceTime
,
NonPointerTime
:
sinceTime
,
},
},
expected
:
url
.
Values
{
"container"
:
{
"mycontainer"
},
"follow"
:
{
"true"
},
"previous"
:
{
"true"
},
"sinceSeconds"
:
{
"123"
},
"emptyTime"
:
{
""
},
"nonPointerTime"
:
{
"2000-01-01T12:34:56Z"
}},
expected
:
url
.
Values
{
"container"
:
{
"mycontainer"
},
"follow"
:
{
"true"
},
"previous"
:
{
"true"
},
"sinceSeconds"
:
{
"123"
},
"
tailLines"
:
{
"0"
},
"
emptyTime"
:
{
""
},
"nonPointerTime"
:
{
"2000-01-01T12:34:56Z"
}},
},
},
}
}
...
...
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