Rename Codec and ResourceVersioner to add Default in front, to allow for types of those names

This commit is contained in:
Daniel Smith
2014-09-05 18:47:09 -07:00
parent 828b70abb9
commit 1c2b65788d
29 changed files with 121 additions and 96 deletions

View File

@@ -222,7 +222,7 @@ func (c *RESTClient) doRequest(request *http.Request) ([]byte, error) {
// Did the server give us a status response?
isStatusResponse := false
var status api.Status
if err := runtime.DecodeInto(body, &status); err == nil && status.Status != "" {
if err := runtime.DefaultCodec.DecodeInto(body, &status); err == nil && status.Status != "" {
isStatusResponse = true
}

View File

@@ -309,7 +309,7 @@ func TestCreateController(t *testing.T) {
func body(obj interface{}, raw *string) *string {
if obj != nil {
bs, _ := runtime.Encode(obj)
bs, _ := runtime.DefaultCodec.Encode(obj)
body := string(bs)
return &body
}
@@ -522,7 +522,7 @@ func TestDoRequest(t *testing.T) {
func TestDoRequestAccepted(t *testing.T) {
status := api.Status{Status: api.StatusWorking}
expectedBody, _ := runtime.Encode(status)
expectedBody, _ := runtime.DefaultCodec.Encode(status)
fakeHandler := util.FakeHandler{
StatusCode: 202,
ResponseBody: string(expectedBody),
@@ -559,7 +559,7 @@ func TestDoRequestAccepted(t *testing.T) {
func TestDoRequestAcceptedSuccess(t *testing.T) {
status := api.Status{Status: api.StatusSuccess}
expectedBody, _ := runtime.Encode(status)
expectedBody, _ := runtime.DefaultCodec.Encode(status)
fakeHandler := util.FakeHandler{
StatusCode: 202,
ResponseBody: string(expectedBody),
@@ -579,7 +579,7 @@ func TestDoRequestAcceptedSuccess(t *testing.T) {
if err != nil {
t.Errorf("Unexpected error %#v", err)
}
statusOut, err := runtime.Decode(body)
statusOut, err := runtime.DefaultCodec.Decode(body)
if err != nil {
t.Errorf("Unexpected error %#v", err)
}

View File

@@ -44,7 +44,7 @@ type Fake struct {
func (c *Fake) ListPods(selector labels.Selector) (api.PodList, error) {
c.Actions = append(c.Actions, FakeAction{Action: "list-pods"})
return *runtime.CopyOrDie(c.Pods).(*api.PodList), nil
return *runtime.DefaultScheme.CopyOrDie(&c.Pods).(*api.PodList), nil
}
func (c *Fake) GetPod(name string) (api.Pod, error) {
@@ -74,7 +74,7 @@ func (c *Fake) ListReplicationControllers(selector labels.Selector) (api.Replica
func (c *Fake) GetReplicationController(name string) (api.ReplicationController, error) {
c.Actions = append(c.Actions, FakeAction{Action: "get-controller", Value: name})
return *runtime.CopyOrDie(c.Ctrl).(*api.ReplicationController), nil
return *runtime.DefaultScheme.CopyOrDie(&c.Ctrl).(*api.ReplicationController), nil
}
func (c *Fake) CreateReplicationController(controller api.ReplicationController) (api.ReplicationController, error) {

View File

@@ -205,7 +205,7 @@ func (r *Request) Body(obj interface{}) *Request {
case io.Reader:
r.body = t
default:
data, err := runtime.Encode(obj)
data, err := runtime.DefaultCodec.Encode(obj)
if err != nil {
r.err = err
return r
@@ -318,7 +318,7 @@ func (r Result) Get() (interface{}, error) {
if r.err != nil {
return nil, r.err
}
return runtime.Decode(r.body)
return runtime.DefaultCodec.Decode(r.body)
}
// Into stores the result into obj, if possible.
@@ -326,7 +326,7 @@ func (r Result) Into(obj interface{}) error {
if r.err != nil {
return r.err
}
return runtime.DecodeInto(r.body, obj)
return runtime.DefaultCodec.DecodeInto(r.body, obj)
}
// Error returns the error executing the request, nil if no error occurred.

View File

@@ -38,7 +38,7 @@ import (
func TestDoRequestNewWay(t *testing.T) {
reqBody := "request body"
expectedObj := &api.Service{Port: 12345}
expectedBody, _ := runtime.Encode(expectedObj)
expectedBody, _ := runtime.DefaultCodec.Encode(expectedObj)
fakeHandler := util.FakeHandler{
StatusCode: 200,
ResponseBody: string(expectedBody),
@@ -71,9 +71,9 @@ func TestDoRequestNewWay(t *testing.T) {
func TestDoRequestNewWayReader(t *testing.T) {
reqObj := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
reqBodyExpected, _ := runtime.Encode(reqObj)
reqBodyExpected, _ := runtime.DefaultCodec.Encode(reqObj)
expectedObj := &api.Service{Port: 12345}
expectedBody, _ := runtime.Encode(expectedObj)
expectedBody, _ := runtime.DefaultCodec.Encode(expectedObj)
fakeHandler := util.FakeHandler{
StatusCode: 200,
ResponseBody: string(expectedBody),
@@ -108,9 +108,9 @@ func TestDoRequestNewWayReader(t *testing.T) {
func TestDoRequestNewWayObj(t *testing.T) {
reqObj := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
reqBodyExpected, _ := runtime.Encode(reqObj)
reqBodyExpected, _ := runtime.DefaultCodec.Encode(reqObj)
expectedObj := &api.Service{Port: 12345}
expectedBody, _ := runtime.Encode(expectedObj)
expectedBody, _ := runtime.DefaultCodec.Encode(expectedObj)
fakeHandler := util.FakeHandler{
StatusCode: 200,
ResponseBody: string(expectedBody),
@@ -144,7 +144,7 @@ func TestDoRequestNewWayObj(t *testing.T) {
func TestDoRequestNewWayFile(t *testing.T) {
reqObj := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
reqBodyExpected, err := runtime.Encode(reqObj)
reqBodyExpected, err := runtime.DefaultCodec.Encode(reqObj)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
@@ -160,7 +160,7 @@ func TestDoRequestNewWayFile(t *testing.T) {
}
expectedObj := &api.Service{Port: 12345}
expectedBody, _ := runtime.Encode(expectedObj)
expectedBody, _ := runtime.DefaultCodec.Encode(expectedObj)
fakeHandler := util.FakeHandler{
StatusCode: 200,
ResponseBody: string(expectedBody),
@@ -295,7 +295,7 @@ func TestPolling(t *testing.T) {
callNumber := 0
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
data, err := runtime.Encode(objects[callNumber])
data, err := runtime.DefaultCodec.Encode(objects[callNumber])
if err != nil {
t.Errorf("Unexpected encode error")
}