Fix includeObject parameter parsing

This commit is contained in:
Jordan Liggitt 2017-08-04 13:25:23 -04:00
parent 8b30aaec39
commit a7a5511480
No known key found for this signature in database
GPG Key ID: 39928704103C7229
4 changed files with 53 additions and 3 deletions

View File

@ -10,6 +10,7 @@ load(
go_library(
name = "go_default_library",
srcs = [
"conversion.go",
"deepcopy.go",
"doc.go",
"generated.pb.go",

View File

@ -0,0 +1,27 @@
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1alpha1
import "k8s.io/apimachinery/pkg/conversion"
// Convert_Slice_string_To_v1alpha1_IncludeObjectPolicy allows converting a URL query parameter value
func Convert_Slice_string_To_v1alpha1_IncludeObjectPolicy(input *[]string, out *IncludeObjectPolicy, s conversion.Scope) error {
if len(*input) > 0 {
*out = IncludeObjectPolicy((*input)[0])
}
return nil
}

View File

@ -46,6 +46,12 @@ func init() {
&PartialObjectMetadataList{},
)
if err := scheme.AddConversionFuncs(
Convert_Slice_string_To_v1alpha1_IncludeObjectPolicy,
); err != nil {
panic(err)
}
// register manually. This usually goes through the SchemeBuilder, which we cannot use here.
//scheme.AddGeneratedDeepCopyFuncs(GetGeneratedDeepCopyFuncs()...)
}

View File

@ -1885,6 +1885,20 @@ func TestGetTable(t *testing.T) {
},
},
},
{
accept: runtime.ContentTypeJSON + ";as=Table;v=v1alpha1;g=meta.k8s.io",
params: url.Values{"includeObject": []string{"Metadata"}},
expected: &metav1alpha1.Table{
TypeMeta: metav1.TypeMeta{Kind: "Table", APIVersion: "meta.k8s.io/v1alpha1"},
ColumnDefinitions: []metav1alpha1.TableColumnDefinition{
{Name: "Name", Type: "string", Description: metaDoc["name"]},
{Name: "Created At", Type: "date", Description: metaDoc["creationTimestamp"]},
},
Rows: []metav1alpha1.TableRow{
{Cells: []interface{}{"foo1", now.Time.UTC().Format(time.RFC3339)}, Object: runtime.RawExtension{Raw: encodedBody}},
},
},
},
}
for i, test := range tests {
u, err := url.Parse(server.URL + "/" + prefix + "/" + testGroupVersion.Group + "/" + testGroupVersion.Version + "/namespaces/default/simple/id")
@ -1901,18 +1915,20 @@ func TestGetTable(t *testing.T) {
}
if test.statusCode != 0 {
if resp.StatusCode != test.statusCode {
t.Errorf("%d: unexpected response: %#v", resp)
t.Errorf("%d: unexpected response: %#v", i, resp)
}
continue
}
if resp.StatusCode != http.StatusOK {
t.Errorf("%d: unexpected response: %#v", resp)
t.Errorf("%d: unexpected response: %#v", i, resp)
}
var itemOut metav1alpha1.Table
if _, err = extractBody(resp, &itemOut); err != nil {
body, err := extractBody(resp, &itemOut)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(test.expected, &itemOut) {
t.Log(body)
t.Errorf("%d: did not match: %s", i, diff.ObjectReflectDiff(test.expected, &itemOut))
}
}