| 1 |
/* |
| 2 |
Copyright 2020 The Kubernetes Authors. |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
package testing |
| 18 |
|
| 19 |
import ( |
| 20 |
"net/url" |
| 21 |
|
| 22 |
"k8s.io/apimachinery/pkg/conversion" |
| 23 |
"k8s.io/apimachinery/pkg/runtime" |
| 24 |
) |
| 25 |
|
| 26 |
func convertUrlValuesToSimpleGetOptions(in *url.Values, out *SimpleGetOptions, s conversion.Scope) error { |
| 27 |
// Skip TypeMeta field. |
| 28 |
|
| 29 |
if values, ok := map[string][]string(*in)["param1"]; ok && len(values) > 0 { |
| 30 |
if err := runtime.Convert_Slice_string_To_string(&values, &out.Param1, s); err != nil { |
| 31 |
return err |
| 32 |
} |
| 33 |
} else { |
| 34 |
out.Param1 = "" |
| 35 |
} |
| 36 |
if values, ok := map[string][]string(*in)["param2"]; ok && len(values) > 0 { |
| 37 |
if err := runtime.Convert_Slice_string_To_string(&values, &out.Param2, s); err != nil { |
| 38 |
return err |
| 39 |
} |
| 40 |
} else { |
| 41 |
out.Param2 = "" |
| 42 |
} |
| 43 |
if values, ok := map[string][]string(*in)["atAPath"]; ok && len(values) > 0 { |
| 44 |
if err := runtime.Convert_Slice_string_To_string(&values, &out.Path, s); err != nil { |
| 45 |
return err |
| 46 |
} |
| 47 |
} else { |
| 48 |
out.Path = "" |
| 49 |
} |
| 50 |
return nil |
| 51 |
} |
| 52 |
|
| 53 |
func RegisterConversions(s *runtime.Scheme) error { |
| 54 |
if err := s.AddConversionFunc((*url.Values)(nil), (*SimpleGetOptions)(nil), func(a, b interface{}, scope conversion.Scope) error { |
| 55 |
return convertUrlValuesToSimpleGetOptions(a.(*url.Values), b.(*SimpleGetOptions), scope) |
| 56 |
}); err != nil { |
| 57 |
return err |
| 58 |
} |
| 59 |
return nil |
| 60 |
} |