mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Merge pull request #60696 from wrfly/patch-1
Automatic merge from submit-queue (batch tested with PRs 60696, 60876, 60901, 60925, 60428). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. fix non-nil ptr in struct convert **What this PR does / why we need it**: Fix an issue. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #35335 **Special notes for your reviewer**: Thanks for other contributer's debug. **Release note**: ```release-note NONE ```
This commit is contained in:
commit
f44f7dffa2
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
|||||||
|
|
||||||
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) {
|
|||||||
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) {
|
|||||||
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"}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user