Make apiserver work with new encode/decode
This commit is contained in:
@@ -26,9 +26,14 @@ import (
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
)
|
||||
|
||||
func init() {
|
||||
api.AddKnownTypes(Simple{}, SimpleList{})
|
||||
}
|
||||
|
||||
// TODO: This doesn't reduce typing enough to make it worth the less readable errors. Remove.
|
||||
func expectNoError(t *testing.T, err error) {
|
||||
if err != nil {
|
||||
@@ -37,11 +42,13 @@ func expectNoError(t *testing.T, err error) {
|
||||
}
|
||||
|
||||
type Simple struct {
|
||||
Name string
|
||||
JSONBase api.JSONBase `json:",inline"`
|
||||
Name string
|
||||
}
|
||||
|
||||
type SimpleList struct {
|
||||
Items []Simple
|
||||
JSONBase api.JSONBase `json:",inline"`
|
||||
Items []Simple
|
||||
}
|
||||
|
||||
type SimpleRESTStorage struct {
|
||||
@@ -54,7 +61,7 @@ type SimpleRESTStorage struct {
|
||||
}
|
||||
|
||||
func (storage *SimpleRESTStorage) List(labels.Selector) (interface{}, error) {
|
||||
result := SimpleList{
|
||||
result := &SimpleList{
|
||||
Items: storage.list,
|
||||
}
|
||||
return result, storage.err
|
||||
@@ -71,7 +78,7 @@ func (storage *SimpleRESTStorage) Delete(id string) (<-chan interface{}, error)
|
||||
|
||||
func (storage *SimpleRESTStorage) Extract(body []byte) (interface{}, error) {
|
||||
var item Simple
|
||||
json.Unmarshal(body, &item)
|
||||
api.DecodeInto(body, &item)
|
||||
return item, storage.err
|
||||
}
|
||||
|
||||
@@ -90,7 +97,7 @@ func extractBody(response *http.Response, object interface{}) (string, error) {
|
||||
if err != nil {
|
||||
return string(body), err
|
||||
}
|
||||
err = json.Unmarshal(body, object)
|
||||
err = api.DecodeInto(body, object)
|
||||
return string(body), err
|
||||
}
|
||||
|
||||
@@ -150,6 +157,7 @@ func TestNonEmptyList(t *testing.T) {
|
||||
body, err := extractBody(resp, &listOut)
|
||||
if len(listOut.Items) != 1 {
|
||||
t.Errorf("Unexpected response: %#v", listOut)
|
||||
return
|
||||
}
|
||||
if listOut.Items[0].Name != simpleStorage.list[0].Name {
|
||||
t.Errorf("Unexpected data: %#v, %s", listOut.Items[0], string(body))
|
||||
|
Reference in New Issue
Block a user