Simple refactor for ease of readability

runtime.DefaultCodec -> latest.Codec
pull/6/head
Clayton Coleman 2014-09-16 15:56:26 -04:00
parent 10f68902f6
commit fe614aeda2
21 changed files with 69 additions and 69 deletions

View File

@ -129,7 +129,7 @@ func readConfig(storage string) []byte {
glog.Fatal("Need config file (-c)") glog.Fatal("Need config file (-c)")
} }
data, err := parser.ToWireFormat(readConfigData(), storage, runtime.DefaultCodec) data, err := parser.ToWireFormat(readConfigData(), storage, latest.Codec)
if err != nil { if err != nil {
glog.Fatalf("Error parsing %v as an object for %v: %v\n", *config, storage, err) glog.Fatalf("Error parsing %v as an object for %v: %v\n", *config, storage, err)
@ -296,7 +296,7 @@ func executeAPIRequest(method string, c *client.Client) bool {
if setBody { if setBody {
if version != 0 { if version != 0 {
data := readConfig(storage) data := readConfig(storage)
obj, err := runtime.DefaultCodec.Decode(data) obj, err := latest.Codec.Decode(data)
if err != nil { if err != nil {
glog.Fatalf("error setting resource version: %v", err) glog.Fatalf("error setting resource version: %v", err)
} }
@ -305,7 +305,7 @@ func executeAPIRequest(method string, c *client.Client) bool {
glog.Fatalf("error setting resource version: %v", err) glog.Fatalf("error setting resource version: %v", err)
} }
jsonBase.SetResourceVersion(version) jsonBase.SetResourceVersion(version)
data, err = runtime.DefaultCodec.Encode(obj) data, err = latest.Codec.Encode(obj)
if err != nil { if err != nil {
glog.Fatalf("error setting resource version: %v", err) glog.Fatalf("error setting resource version: %v", err)
} }

View File

@ -103,7 +103,7 @@ func TestApiExamples(t *testing.T) {
return return
} }
tested += 1 tested += 1
if err := runtime.DefaultCodec.DecodeInto(data, expectedType); err != nil { if err := latest.Codec.DecodeInto(data, expectedType); err != nil {
t.Errorf("%s did not decode correctly: %v\n%s", path, err, string(data)) t.Errorf("%s did not decode correctly: %v\n%s", path, err, string(data))
return return
} }
@ -137,7 +137,7 @@ func TestExamples(t *testing.T) {
return return
} }
tested += 1 tested += 1
if err := runtime.DefaultCodec.DecodeInto(data, expectedType); err != nil { if err := latest.Codec.DecodeInto(data, expectedType); err != nil {
t.Errorf("%s did not decode correctly: %v\n%s", path, err, string(data)) t.Errorf("%s did not decode correctly: %v\n%s", path, err, string(data))
return return
} }
@ -168,14 +168,14 @@ func TestReadme(t *testing.T) {
} }
for _, json := range match[1:] { for _, json := range match[1:] {
expectedType := &api.Pod{} expectedType := &api.Pod{}
if err := runtime.DefaultCodec.DecodeInto([]byte(json), expectedType); err != nil { if err := latest.Codec.DecodeInto([]byte(json), expectedType); err != nil {
t.Errorf("%s did not decode correctly: %v\n%s", path, err, string(data)) t.Errorf("%s did not decode correctly: %v\n%s", path, err, string(data))
return return
} }
if errors := validateObject(expectedType); len(errors) > 0 { if errors := validateObject(expectedType); len(errors) > 0 {
t.Errorf("%s did not validate correctly: %v", path, errors) t.Errorf("%s did not validate correctly: %v", path, errors)
} }
encoded, err := runtime.DefaultCodec.Encode(expectedType) encoded, err := latest.Codec.Encode(expectedType)
if err != nil { if err != nil {
t.Errorf("Could not encode object: %v", err) t.Errorf("Could not encode object: %v", err)
continue continue

View File

@ -135,13 +135,13 @@ func runTest(t *testing.T, source runtime.Object) {
j.SetKind("") j.SetKind("")
j.SetAPIVersion("") j.SetAPIVersion("")
data, err := runtime.DefaultCodec.Encode(source) data, err := latest.Codec.Encode(source)
if err != nil { if err != nil {
t.Errorf("%v: %v (%#v)", name, err, source) t.Errorf("%v: %v (%#v)", name, err, source)
return return
} }
obj2, err := runtime.DefaultCodec.Decode(data) obj2, err := latest.Codec.Decode(data)
if err != nil { if err != nil {
t.Errorf("%v: %v", name, err) t.Errorf("%v: %v", name, err)
return return
@ -152,7 +152,7 @@ func runTest(t *testing.T, source runtime.Object) {
} }
} }
obj3 := reflect.New(reflect.TypeOf(source).Elem()).Interface().(runtime.Object) obj3 := reflect.New(reflect.TypeOf(source).Elem()).Interface().(runtime.Object)
err = runtime.DefaultCodec.DecodeInto(data, obj3) err = latest.Codec.DecodeInto(data, obj3)
if err != nil { if err != nil {
t.Errorf("2: %v: %v", name, err) t.Errorf("2: %v: %v", name, err)
return return
@ -194,8 +194,8 @@ func TestEncode_Ptr(t *testing.T) {
Labels: map[string]string{"name": "foo"}, Labels: map[string]string{"name": "foo"},
} }
obj := runtime.Object(pod) obj := runtime.Object(pod)
data, err := runtime.DefaultCodec.Encode(obj) data, err := latest.Codec.Encode(obj)
obj2, err2 := runtime.DefaultCodec.Decode(data) obj2, err2 := latest.Codec.Decode(data)
if err != nil || err2 != nil { if err != nil || err2 != nil {
t.Fatalf("Failure: '%v' '%v'", err, err2) t.Fatalf("Failure: '%v' '%v'", err, err2)
} }
@ -209,11 +209,11 @@ func TestEncode_Ptr(t *testing.T) {
func TestBadJSONRejection(t *testing.T) { func TestBadJSONRejection(t *testing.T) {
badJSONMissingKind := []byte(`{ }`) badJSONMissingKind := []byte(`{ }`)
if _, err := runtime.DefaultCodec.Decode(badJSONMissingKind); err == nil { if _, err := latest.Codec.Decode(badJSONMissingKind); err == nil {
t.Errorf("Did not reject despite lack of kind field: %s", badJSONMissingKind) t.Errorf("Did not reject despite lack of kind field: %s", badJSONMissingKind)
} }
badJSONUnknownType := []byte(`{"kind": "bar"}`) badJSONUnknownType := []byte(`{"kind": "bar"}`)
if _, err1 := runtime.DefaultCodec.Decode(badJSONUnknownType); err1 == nil { if _, err1 := latest.Codec.Decode(badJSONUnknownType); err1 == nil {
t.Errorf("Did not reject despite use of unknown type: %s", badJSONUnknownType) t.Errorf("Did not reject despite use of unknown type: %s", badJSONUnknownType)
} }
/*badJSONKindMismatch := []byte(`{"kind": "Pod"}`) /*badJSONKindMismatch := []byte(`{"kind": "Pod"}`)

View File

@ -43,7 +43,7 @@ func convert(obj runtime.Object) (runtime.Object, error) {
return obj, nil return obj, nil
} }
var codec = runtime.DefaultCodec var codec = latest.Codec
func init() { func init() {
runtime.DefaultScheme.AddKnownTypes("", &Simple{}, &SimpleList{}) runtime.DefaultScheme.AddKnownTypes("", &Simple{}, &SimpleList{})
@ -676,7 +676,7 @@ func (*UnregisteredAPIObject) IsAnAPIObject() {}
func TestWriteJSONDecodeError(t *testing.T) { func TestWriteJSONDecodeError(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
writeJSON(http.StatusOK, runtime.DefaultCodec, &UnregisteredAPIObject{"Undecodable"}, w) writeJSON(http.StatusOK, latest.Codec, &UnregisteredAPIObject{"Undecodable"}, w)
})) }))
status := expectApiStatus(t, "GET", server.URL, nil, http.StatusInternalServerError) status := expectApiStatus(t, "GET", server.URL, nil, http.StatusInternalServerError)
if status.Reason != api.StatusReasonUnknown { if status.Reason != api.StatusReasonUnknown {

View File

@ -99,7 +99,7 @@ type Client struct {
// to a URL will prepend the server path. Returns an error if host cannot be converted to a // to a URL will prepend the server path. Returns an error if host cannot be converted to a
// valid URL. // valid URL.
func New(host string, auth *AuthInfo) (*Client, error) { func New(host string, auth *AuthInfo) (*Client, error) {
restClient, err := NewRESTClient(host, auth, "/api/v1beta1/", runtime.DefaultCodec) restClient, err := NewRESTClient(host, auth, "/api/v1beta1/", latest.Codec)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -224,7 +224,7 @@ func (c *RESTClient) doRequest(request *http.Request) ([]byte, error) {
// Did the server give us a status response? // Did the server give us a status response?
isStatusResponse := false isStatusResponse := false
var status api.Status var status api.Status
if err := runtime.DefaultCodec.DecodeInto(body, &status); err == nil && status.Status != "" { if err := latest.Codec.DecodeInto(body, &status); err == nil && status.Status != "" {
isStatusResponse = true isStatusResponse = true
} }

View File

@ -48,7 +48,7 @@ func TestValidatesHostParameter(t *testing.T) {
"host/server": {"", "", true}, "host/server": {"", "", true},
} }
for k, expected := range testCases { for k, expected := range testCases {
c, err := NewRESTClient(k, nil, "/api/v1beta1/", runtime.DefaultCodec) c, err := NewRESTClient(k, nil, "/api/v1beta1/", latest.Codec)
switch { switch {
case err == nil && expected.Err: case err == nil && expected.Err:
t.Errorf("expected error but was nil") t.Errorf("expected error but was nil")
@ -309,7 +309,7 @@ func TestCreateController(t *testing.T) {
func body(obj runtime.Object, raw *string) *string { func body(obj runtime.Object, raw *string) *string {
if obj != nil { if obj != nil {
bs, _ := runtime.DefaultCodec.Encode(obj) bs, _ := latest.Codec.Encode(obj)
body := string(bs) body := string(bs)
return &body return &body
} }
@ -533,7 +533,7 @@ func TestDoRequest(t *testing.T) {
func TestDoRequestAccepted(t *testing.T) { func TestDoRequestAccepted(t *testing.T) {
status := &api.Status{Status: api.StatusWorking} status := &api.Status{Status: api.StatusWorking}
expectedBody, _ := runtime.DefaultCodec.Encode(status) expectedBody, _ := latest.Codec.Encode(status)
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 202, StatusCode: 202,
ResponseBody: string(expectedBody), ResponseBody: string(expectedBody),
@ -570,7 +570,7 @@ func TestDoRequestAccepted(t *testing.T) {
func TestDoRequestAcceptedSuccess(t *testing.T) { func TestDoRequestAcceptedSuccess(t *testing.T) {
status := &api.Status{Status: api.StatusSuccess} status := &api.Status{Status: api.StatusSuccess}
expectedBody, _ := runtime.DefaultCodec.Encode(status) expectedBody, _ := latest.Codec.Encode(status)
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 202, StatusCode: 202,
ResponseBody: string(expectedBody), ResponseBody: string(expectedBody),
@ -590,7 +590,7 @@ func TestDoRequestAcceptedSuccess(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Unexpected error %#v", err) t.Errorf("Unexpected error %#v", err)
} }
statusOut, err := runtime.DefaultCodec.Decode(body) statusOut, err := latest.Codec.Decode(body)
if err != nil { if err != nil {
t.Errorf("Unexpected error %#v", err) t.Errorf("Unexpected error %#v", err)
} }

View File

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

View File

@ -109,7 +109,7 @@ func validateSyncReplication(t *testing.T, fakePodControl *FakePodControl, expec
} }
func TestSyncReplicationControllerDoesNothing(t *testing.T) { func TestSyncReplicationControllerDoesNothing(t *testing.T) {
body, _ := runtime.DefaultCodec.Encode(newPodList(2)) body, _ := latest.Codec.Encode(newPodList(2))
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 200, StatusCode: 200,
ResponseBody: string(body), ResponseBody: string(body),
@ -129,7 +129,7 @@ func TestSyncReplicationControllerDoesNothing(t *testing.T) {
} }
func TestSyncReplicationControllerDeletes(t *testing.T) { func TestSyncReplicationControllerDeletes(t *testing.T) {
body, _ := runtime.DefaultCodec.Encode(newPodList(2)) body, _ := latest.Codec.Encode(newPodList(2))
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 200, StatusCode: 200,
ResponseBody: string(body), ResponseBody: string(body),
@ -149,7 +149,7 @@ func TestSyncReplicationControllerDeletes(t *testing.T) {
} }
func TestSyncReplicationControllerCreates(t *testing.T) { func TestSyncReplicationControllerCreates(t *testing.T) {
body, _ := runtime.DefaultCodec.Encode(newPodList(0)) body, _ := latest.Codec.Encode(newPodList(0))
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 200, StatusCode: 200,
ResponseBody: string(body), ResponseBody: string(body),
@ -169,7 +169,7 @@ func TestSyncReplicationControllerCreates(t *testing.T) {
} }
func TestCreateReplica(t *testing.T) { func TestCreateReplica(t *testing.T) {
body, _ := runtime.DefaultCodec.Encode(&api.Pod{}) body, _ := latest.Codec.Encode(&api.Pod{})
fakeHandler := util.FakeHandler{ fakeHandler := util.FakeHandler{
StatusCode: 200, StatusCode: 200,
ResponseBody: string(body), ResponseBody: string(body),

View File

@ -27,21 +27,21 @@ import (
func TestParseBadStorage(t *testing.T) { func TestParseBadStorage(t *testing.T) {
p := NewParser(map[string]runtime.Object{}) p := NewParser(map[string]runtime.Object{})
_, err := p.ToWireFormat([]byte("{}"), "badstorage", runtime.DefaultCodec) _, err := p.ToWireFormat([]byte("{}"), "badstorage", latest.Codec)
if err == nil { if err == nil {
t.Errorf("Expected error, received none") t.Errorf("Expected error, received none")
} }
} }
func DoParseTest(t *testing.T, storage string, obj runtime.Object, p *Parser) { func DoParseTest(t *testing.T, storage string, obj runtime.Object, p *Parser) {
jsonData, _ := runtime.DefaultCodec.Encode(obj) jsonData, _ := latest.Codec.Encode(obj)
var tmp map[string]interface{} var tmp map[string]interface{}
json.Unmarshal(jsonData, &tmp) json.Unmarshal(jsonData, &tmp)
yamlData, _ := yaml.Marshal(tmp) yamlData, _ := yaml.Marshal(tmp)
t.Logf("Intermediate yaml:\n%v\n", string(yamlData)) t.Logf("Intermediate yaml:\n%v\n", string(yamlData))
t.Logf("Intermediate json:\n%v\n", string(jsonData)) t.Logf("Intermediate json:\n%v\n", string(jsonData))
jsonGot, jsonErr := p.ToWireFormat(jsonData, storage, runtime.DefaultCodec) jsonGot, jsonErr := p.ToWireFormat(jsonData, storage, latest.Codec)
yamlGot, yamlErr := p.ToWireFormat(yamlData, storage, runtime.DefaultCodec) yamlGot, yamlErr := p.ToWireFormat(yamlData, storage, latest.Codec)
if jsonErr != nil { if jsonErr != nil {
t.Errorf("json err: %#v", jsonErr) t.Errorf("json err: %#v", jsonErr)

View File

@ -53,7 +53,7 @@ func (s *ProxyServer) Serve() error {
func (s *ProxyServer) doError(w http.ResponseWriter, err error) { func (s *ProxyServer) doError(w http.ResponseWriter, err error) {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
w.Header().Add("Content-type", "application/json") w.Header().Add("Content-type", "application/json")
data, _ := runtime.DefaultCodec.Encode(&api.Status{ data, _ := latest.Codec.Encode(&api.Status{
Status: api.StatusFailure, Status: api.StatusFailure,
Message: fmt.Sprintf("internal error: %#v", err), Message: fmt.Sprintf("internal error: %#v", err),
}) })

View File

@ -50,7 +50,7 @@ func (i *IdentityPrinter) Print(data []byte, w io.Writer) error {
// PrintObj is an implementation of ResourcePrinter.PrintObj which simply writes the object to the Writer. // PrintObj is an implementation of ResourcePrinter.PrintObj which simply writes the object to the Writer.
func (i *IdentityPrinter) PrintObj(obj runtime.Object, output io.Writer) error { func (i *IdentityPrinter) PrintObj(obj runtime.Object, output io.Writer) error {
data, err := runtime.DefaultCodec.Encode(obj) data, err := latest.Codec.Encode(obj)
if err != nil { if err != nil {
return err return err
} }
@ -260,7 +260,7 @@ func (h *HumanReadablePrinter) Print(data []byte, output io.Writer) error {
return fmt.Errorf("unexpected object with no 'kind' field: %s", data) return fmt.Errorf("unexpected object with no 'kind' field: %s", data)
} }
obj, err := runtime.DefaultCodec.Decode(data) obj, err := latest.Codec.Decode(data)
if err != nil { if err != nil {
return err return err
} }
@ -292,7 +292,7 @@ type TemplatePrinter struct {
// Print parses the data as JSON, and re-formats it with the Go Template. // Print parses the data as JSON, and re-formats it with the Go Template.
func (t *TemplatePrinter) Print(data []byte, w io.Writer) error { func (t *TemplatePrinter) Print(data []byte, w io.Writer) error {
obj, err := runtime.DefaultCodec.Decode(data) obj, err := latest.Codec.Decode(data)
if err != nil { if err != nil {
return err return err
} }

View File

@ -96,7 +96,7 @@ func TestIdentityPrinter(t *testing.T) {
} }
buff.Reset() buff.Reset()
printer.PrintObj(obj, buff) printer.PrintObj(obj, buff)
objOut, err := runtime.DefaultCodec.Decode([]byte(buff.String())) objOut, err := latest.Codec.Decode([]byte(buff.String()))
if err != nil { if err != nil {
t.Errorf("Unexpeted error: %#v", err) t.Errorf("Unexpeted error: %#v", err)
} }

View File

@ -47,7 +47,7 @@ type SourceEtcd struct {
func NewSourceEtcd(key string, client tools.EtcdClient, updates chan<- interface{}) *SourceEtcd { func NewSourceEtcd(key string, client tools.EtcdClient, updates chan<- interface{}) *SourceEtcd {
helper := tools.EtcdHelper{ helper := tools.EtcdHelper{
client, client,
runtime.DefaultCodec, latest.Codec,
runtime.DefaultResourceVersioner, runtime.DefaultResourceVersioner,
} }
source := &SourceEtcd{ source := &SourceEtcd{

View File

@ -135,7 +135,7 @@ func (s ConfigSourceEtcd) GetServices() ([]api.Service, []api.Endpoints, error)
// and create a Service entry for it. // and create a Service entry for it.
for i, node := range response.Node.Nodes { for i, node := range response.Node.Nodes {
var svc api.Service var svc api.Service
err = runtime.DefaultCodec.DecodeInto([]byte(node.Value), &svc) err = latest.Codec.DecodeInto([]byte(node.Value), &svc)
if err != nil { if err != nil {
glog.Errorf("Failed to load Service: %s (%#v)", node.Value, err) glog.Errorf("Failed to load Service: %s (%#v)", node.Value, err)
continue continue
@ -168,7 +168,7 @@ func (s ConfigSourceEtcd) GetEndpoints(service string) (api.Endpoints, error) {
} }
// Parse all the endpoint specifications in this value. // Parse all the endpoint specifications in this value.
var e api.Endpoints var e api.Endpoints
err = runtime.DefaultCodec.DecodeInto([]byte(response.Node.Value), &e) err = latest.Codec.DecodeInto([]byte(response.Node.Value), &e)
return e, err return e, err
} }
@ -178,7 +178,7 @@ func etcdResponseToService(response *etcd.Response) (*api.Service, error) {
return nil, fmt.Errorf("invalid response from etcd: %#v", response) return nil, fmt.Errorf("invalid response from etcd: %#v", response)
} }
var svc api.Service var svc api.Service
err := runtime.DefaultCodec.DecodeInto([]byte(response.Node.Value), &svc) err := latest.Codec.DecodeInto([]byte(response.Node.Value), &svc)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -232,7 +232,7 @@ func (s ConfigSourceEtcd) ProcessChange(response *etcd.Response) {
func (s ConfigSourceEtcd) ProcessEndpointResponse(response *etcd.Response) { func (s ConfigSourceEtcd) ProcessEndpointResponse(response *etcd.Response) {
glog.Infof("Processing a change in endpoint configuration... %s", *response) glog.Infof("Processing a change in endpoint configuration... %s", *response)
var endpoints api.Endpoints var endpoints api.Endpoints
err := runtime.DefaultCodec.DecodeInto([]byte(response.Node.Value), &endpoints) err := latest.Codec.DecodeInto([]byte(response.Node.Value), &endpoints)
if err != nil { if err != nil {
glog.Errorf("Failed to parse service out of etcd key: %v : %+v", response.Node.Value, err) glog.Errorf("Failed to parse service out of etcd key: %v : %+v", response.Node.Value, err)
return return

View File

@ -38,12 +38,12 @@ func TestNewREST(t *testing.T) {
PodID: "foo", PodID: "foo",
Host: "bar", Host: "bar",
} }
body, err := runtime.DefaultCodec.Encode(binding) body, err := latest.Codec.Encode(binding)
if err != nil { if err != nil {
t.Fatalf("Unexpected encode error %v", err) t.Fatalf("Unexpected encode error %v", err)
} }
obj := b.New() obj := b.New()
err = runtime.DefaultCodec.DecodeInto(body, obj) err = latest.Codec.DecodeInto(body, obj)
if err != nil { if err != nil {
t.Fatalf("Unexpected error %v", err) t.Fatalf("Unexpected error %v", err)
} }

View File

@ -113,13 +113,13 @@ func TestControllerDecode(t *testing.T) {
ID: "foo", ID: "foo",
}, },
} }
body, err := runtime.DefaultCodec.Encode(controller) body, err := latest.Codec.Encode(controller)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
controllerOut := storage.New() controllerOut := storage.New()
if err := runtime.DefaultCodec.DecodeInto(body, controllerOut); err != nil { if err := latest.Codec.DecodeInto(body, controllerOut); err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }

View File

@ -45,7 +45,7 @@ func NewRegistry(client tools.EtcdClient) *Registry {
registry := &Registry{ registry := &Registry{
EtcdHelper: tools.EtcdHelper{ EtcdHelper: tools.EtcdHelper{
client, client,
runtime.DefaultCodec, latest.Codec,
runtime.DefaultResourceVersioner, runtime.DefaultResourceVersioner,
}, },
} }

View File

@ -108,7 +108,7 @@ func TestEtcdCreatePod(t *testing.T) {
t.Fatalf("Unexpected error %v", err) t.Fatalf("Unexpected error %v", err)
} }
var pod api.Pod var pod api.Pod
err = runtime.DefaultCodec.DecodeInto([]byte(resp.Node.Value), &pod) err = latest.Codec.DecodeInto([]byte(resp.Node.Value), &pod)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
@ -122,7 +122,7 @@ func TestEtcdCreatePod(t *testing.T) {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
err = runtime.DefaultCodec.DecodeInto([]byte(resp.Node.Value), &manifests) err = latest.Codec.DecodeInto([]byte(resp.Node.Value), &manifests)
if len(manifests.Items) != 1 || manifests.Items[0].ID != "foo" { if len(manifests.Items) != 1 || manifests.Items[0].ID != "foo" {
t.Errorf("Unexpected manifest list: %#v", manifests) t.Errorf("Unexpected manifest list: %#v", manifests)
} }
@ -235,7 +235,7 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) {
t.Fatalf("Unexpected error %v", err) t.Fatalf("Unexpected error %v", err)
} }
var pod api.Pod var pod api.Pod
err = runtime.DefaultCodec.DecodeInto([]byte(resp.Node.Value), &pod) err = latest.Codec.DecodeInto([]byte(resp.Node.Value), &pod)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
@ -249,7 +249,7 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
err = runtime.DefaultCodec.DecodeInto([]byte(resp.Node.Value), &manifests) err = latest.Codec.DecodeInto([]byte(resp.Node.Value), &manifests)
if len(manifests.Items) != 1 || manifests.Items[0].ID != "foo" { if len(manifests.Items) != 1 || manifests.Items[0].ID != "foo" {
t.Errorf("Unexpected manifest list: %#v", manifests) t.Errorf("Unexpected manifest list: %#v", manifests)
} }
@ -300,7 +300,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
t.Fatalf("Unexpected error %v", err) t.Fatalf("Unexpected error %v", err)
} }
var pod api.Pod var pod api.Pod
err = runtime.DefaultCodec.DecodeInto([]byte(resp.Node.Value), &pod) err = latest.Codec.DecodeInto([]byte(resp.Node.Value), &pod)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
@ -314,7 +314,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
err = runtime.DefaultCodec.DecodeInto([]byte(resp.Node.Value), &manifests) err = latest.Codec.DecodeInto([]byte(resp.Node.Value), &manifests)
if len(manifests.Items) != 2 || manifests.Items[1].ID != "foo" { if len(manifests.Items) != 2 || manifests.Items[1].ID != "foo" {
t.Errorf("Unexpected manifest list: %#v", manifests) t.Errorf("Unexpected manifest list: %#v", manifests)
} }
@ -350,7 +350,7 @@ func TestEtcdDeletePod(t *testing.T) {
t.Fatalf("Unexpected error %v", err) t.Fatalf("Unexpected error %v", err)
} }
var manifests api.ContainerManifestList var manifests api.ContainerManifestList
runtime.DefaultCodec.DecodeInto([]byte(response.Node.Value), &manifests) latest.Codec.DecodeInto([]byte(response.Node.Value), &manifests)
if len(manifests.Items) != 0 { if len(manifests.Items) != 0 {
t.Errorf("Unexpected container set: %s, expected empty", response.Node.Value) t.Errorf("Unexpected container set: %s, expected empty", response.Node.Value)
} }
@ -388,7 +388,7 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) {
t.Fatalf("Unexpected error %v", err) t.Fatalf("Unexpected error %v", err)
} }
var manifests api.ContainerManifestList var manifests api.ContainerManifestList
runtime.DefaultCodec.DecodeInto([]byte(response.Node.Value), &manifests) latest.Codec.DecodeInto([]byte(response.Node.Value), &manifests)
if len(manifests.Items) != 1 { if len(manifests.Items) != 1 {
t.Fatalf("Unexpected manifest set: %#v, expected empty", manifests) t.Fatalf("Unexpected manifest set: %#v, expected empty", manifests)
} }
@ -607,7 +607,7 @@ func TestEtcdCreateController(t *testing.T) {
t.Fatalf("Unexpected error %v", err) t.Fatalf("Unexpected error %v", err)
} }
var ctrl api.ReplicationController var ctrl api.ReplicationController
err = runtime.DefaultCodec.DecodeInto([]byte(resp.Node.Value), &ctrl) err = latest.Codec.DecodeInto([]byte(resp.Node.Value), &ctrl)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
@ -699,7 +699,7 @@ func TestEtcdCreateService(t *testing.T) {
} }
var service api.Service var service api.Service
err = runtime.DefaultCodec.DecodeInto([]byte(resp.Node.Value), &service) err = latest.Codec.DecodeInto([]byte(resp.Node.Value), &service)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
@ -874,7 +874,7 @@ func TestEtcdUpdateEndpoints(t *testing.T) {
t.Fatalf("Unexpected error %v", err) t.Fatalf("Unexpected error %v", err)
} }
var endpointsOut api.Endpoints var endpointsOut api.Endpoints
err = runtime.DefaultCodec.DecodeInto([]byte(response.Node.Value), &endpointsOut) err = latest.Codec.DecodeInto([]byte(response.Node.Value), &endpointsOut)
if !reflect.DeepEqual(endpoints, endpointsOut) { if !reflect.DeepEqual(endpoints, endpointsOut) {
t.Errorf("Unexpected endpoints: %#v, expected %#v", endpointsOut, endpoints) t.Errorf("Unexpected endpoints: %#v, expected %#v", endpointsOut, endpoints)
} }

View File

@ -201,13 +201,13 @@ func TestPodDecode(t *testing.T) {
ID: "foo", ID: "foo",
}, },
} }
body, err := runtime.DefaultCodec.Encode(expected) body, err := latest.Codec.Encode(expected)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
actual := storage.New() actual := storage.New()
if err := runtime.DefaultCodec.DecodeInto(body, actual); err != nil { if err := latest.Codec.DecodeInto(body, actual); err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }

View File

@ -42,7 +42,7 @@ type TestResource struct {
func (*TestResource) IsAnAPIObject() {} func (*TestResource) IsAnAPIObject() {}
var scheme *runtime.Scheme var scheme *runtime.Scheme
var codec = runtime.DefaultCodec var codec = latest.Codec
var versioner = runtime.DefaultResourceVersioner var versioner = runtime.DefaultResourceVersioner
func init() { func init() {

View File

@ -90,7 +90,7 @@ func TestExtractObj(t *testing.T) {
func TestWatch(t *testing.T) { func TestWatch(t *testing.T) {
client := newEtcdClient() client := newEtcdClient()
helper := tools.EtcdHelper{Client: client, Codec: runtime.DefaultCodec, ResourceVersioner: runtime.DefaultResourceVersioner} helper := tools.EtcdHelper{Client: client, Codec: latest.Codec, ResourceVersioner: runtime.DefaultResourceVersioner}
withEtcdKey(func(key string) { withEtcdKey(func(key string) {
resp, err := client.Set(key, runtime.DefaultScheme.EncodeOrDie(&api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), 0) resp, err := client.Set(key, runtime.DefaultScheme.EncodeOrDie(&api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), 0)
if err != nil { if err != nil {