Add conversion to properly parse query parameter propagationPolicy

This commit is contained in:
Haowei Cai 2018-05-03 16:12:10 -07:00
parent 88c25ca2d9
commit 294e00c669
2 changed files with 47 additions and 0 deletions

View File

@ -75,6 +75,8 @@ func AddConversionFuncs(scheme *runtime.Scheme) error {
Convert_unversioned_LabelSelector_to_map,
Convert_Slice_string_To_Slice_int32,
Convert_Slice_string_To_v1_DeletionPropagation,
)
}
@ -304,3 +306,13 @@ func Convert_Slice_string_To_Slice_int32(in *[]string, out *[]int32, s conversio
}
return nil
}
// Convert_Slice_string_To_v1_DeletionPropagation allows converting a URL query parameter propagationPolicy
func Convert_Slice_string_To_v1_DeletionPropagation(input *[]string, out *DeletionPropagation, s conversion.Scope) error {
if len(*input) > 0 {
*out = DeletionPropagation((*input)[0])
} else {
*out = ""
}
return nil
}

View File

@ -47,3 +47,38 @@ func TestMapToLabelSelectorRoundTrip(t *testing.T) {
}
}
}
func TestConvertSliceStringToDeletionPropagation(t *testing.T) {
tcs := []struct {
Input []string
Output v1.DeletionPropagation
}{
{
Input: nil,
Output: "",
},
{
Input: []string{},
Output: "",
},
{
Input: []string{"foo"},
Output: "foo",
},
{
Input: []string{"bar", "foo"},
Output: "bar",
},
}
for _, tc := range tcs {
var dp v1.DeletionPropagation
if err := v1.Convert_Slice_string_To_v1_DeletionPropagation(&tc.Input, &dp, nil); err != nil {
t.Errorf("Convert_Slice_string_To_v1_DeletionPropagation(%#v): %v", tc.Input, err)
continue
}
if !apiequality.Semantic.DeepEqual(dp, tc.Output) {
t.Errorf("slice string to DeletionPropagation conversion failed: got %v; want %v", dp, tc.Output)
}
}
}