Skip to content

Commit

Permalink
Merge pull request kubernetes#18487 from smarterclayton/guard_encode_…
Browse files Browse the repository at this point in the history
…decode

Auto commit by PR queue bot
  • Loading branch information
k8s-merge-robot committed Dec 14, 2015
2 parents 9067833 + 1e21054 commit 266ab4a
Show file tree
Hide file tree
Showing 25 changed files with 103 additions and 81 deletions.
2 changes: 1 addition & 1 deletion examples/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func TestExampleObjectSchemas(t *testing.T) {
if err != nil {
t.Errorf("Could not get codec for %s: %s", expectedType, err)
}
if err := codec.DecodeInto(data, expectedType); err != nil {
if err := runtime.DecodeInto(codec, data, expectedType); err != nil {
t.Errorf("%s did not decode correctly: %v\n%s", path, err, string(data))
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func AddToNodeAddresses(addresses *[]NodeAddress, addAddresses ...NodeAddress) {
}

func HashObject(obj runtime.Object, codec runtime.Codec) (string, error) {
data, err := codec.Encode(obj)
data, err := runtime.Encode(codec, obj)
if err != nil {
return "", err
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/api/serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ func roundTrip(t *testing.T, codec runtime.Codec, item runtime.Object) {
t.Logf("fully qualified kind for %v is %v with codec %v", reflect.TypeOf(item), gvk, codec)

name := reflect.TypeOf(item).Elem().Name()
data, err := codec.Encode(item)
data, err := runtime.Encode(codec, item)
if err != nil {
t.Errorf("%v: %v (%s)", name, err, printer.Sprintf("%#v", item))
return
}

obj2, err := codec.Decode(data)
obj2, err := runtime.Decode(codec, data)
if err != nil {
t.Errorf("0: %v: %v\nCodec: %v\nData: %s\nSource: %#v", name, err, codec, string(data), printer.Sprintf("%#v", item))
return
Expand All @@ -84,7 +84,7 @@ func roundTrip(t *testing.T, codec runtime.Codec, item runtime.Object) {
}

obj3 := reflect.New(reflect.TypeOf(item).Elem()).Interface().(runtime.Object)
err = codec.DecodeInto(data, obj3)
err = runtime.DecodeInto(codec, data, obj3)
if err != nil {
t.Errorf("2: %v: %v", name, err)
return
Expand Down Expand Up @@ -307,7 +307,7 @@ func BenchmarkDecodeCodec(b *testing.B) {
width := len(items)
encoded := make([][]byte, width)
for i := range items {
data, err := codec.Encode(&items[i])
data, err := runtime.Encode(codec, &items[i])
if err != nil {
b.Fatal(err)
}
Expand All @@ -316,7 +316,7 @@ func BenchmarkDecodeCodec(b *testing.B) {

b.ResetTimer()
for i := 0; i < b.N; i++ {
if _, err := codec.Decode(encoded[i%width]); err != nil {
if _, err := runtime.Decode(codec, encoded[i%width]); err != nil {
b.Fatal(err)
}
}
Expand All @@ -329,7 +329,7 @@ func BenchmarkDecodeIntoCodec(b *testing.B) {
width := len(items)
encoded := make([][]byte, width)
for i := range items {
data, err := codec.Encode(&items[i])
data, err := runtime.Encode(codec, &items[i])
if err != nil {
b.Fatal(err)
}
Expand All @@ -339,7 +339,7 @@ func BenchmarkDecodeIntoCodec(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
obj := v1.Pod{}
if err := codec.DecodeInto(encoded[i%width], &obj); err != nil {
if err := runtime.DecodeInto(codec, encoded[i%width], &obj); err != nil {
b.Fatal(err)
}
}
Expand All @@ -353,7 +353,7 @@ func BenchmarkDecodeIntoJSON(b *testing.B) {
width := len(items)
encoded := make([][]byte, width)
for i := range items {
data, err := codec.Encode(&items[i])
data, err := runtime.Encode(codec, &items[i])
if err != nil {
b.Fatal(err)
}
Expand All @@ -377,7 +377,7 @@ func BenchmarkDecodeIntoJSONCodecGen(b *testing.B) {
width := len(items)
encoded := make([][]byte, width)
for i := range items {
data, err := kcodec.Encode(&items[i])
data, err := runtime.Encode(kcodec, &items[i])
if err != nil {
b.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/testing/compat/compatibility_tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestCompatibility(

// Decode
codec := runtime.CodecFor(api.Scheme, version)
obj, err := codec.Decode(input)
obj, err := runtime.Decode(codec, input)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
Expand All @@ -60,7 +60,7 @@ func TestCompatibility(
}

// Encode
output, err := codec.Encode(obj)
output, err := runtime.Encode(codec, obj)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/extensions/v1beta1/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func TestSetDefaultJob(t *testing.T) {
}

func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
data, err := Codec.Encode(obj)
data, err := runtime.Encode(Codec, obj)
if err != nil {
t.Errorf("%v\n %#v", err, obj)
return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func writeJSON(statusCode int, codec runtime.Codec, object runtime.Object, w htt

func prettyJSON(codec runtime.Codec, object runtime.Object, w http.ResponseWriter) {
formatted := &bytes.Buffer{}
output, err := codec.Encode(object)
output, err := runtime.Encode(codec, object)
if err != nil {
errorJSONFatal(err, codec, w)
}
Expand All @@ -432,7 +432,7 @@ func errorJSONFatal(err error, codec runtime.Codec, w http.ResponseWriter) int {
util.HandleError(fmt.Errorf("apiserver was unable to write a JSON response: %v", err))
status := errToAPIStatus(err)
code := int(status.Code)
output, err := codec.Encode(status)
output, err := runtime.Encode(codec, status)
if err != nil {
w.WriteHeader(code)
fmt.Fprintf(w, "%s: %s", status.Reason, status.Message)
Expand Down
54 changes: 27 additions & 27 deletions pkg/apiserver/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@ func handleInternal(storage map[string]rest.Storage, admissionControl admission.

func TestSimpleSetupRight(t *testing.T) {
s := &apiservertesting.Simple{ObjectMeta: api.ObjectMeta{Name: "aName"}}
wire, err := codec.Encode(s)
wire, err := runtime.Encode(codec, s)
if err != nil {
t.Fatal(err)
}
s2, err := codec.Decode(wire)
s2, err := runtime.Decode(codec, wire)
if err != nil {
t.Fatal(err)
}
Expand All @@ -287,11 +287,11 @@ func TestSimpleSetupRight(t *testing.T) {

func TestSimpleOptionsSetupRight(t *testing.T) {
s := &apiservertesting.SimpleGetOptions{}
wire, err := codec.Encode(s)
wire, err := runtime.Encode(codec, s)
if err != nil {
t.Fatal(err)
}
s2, err := codec.Decode(wire)
s2, err := runtime.Decode(codec, wire)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -614,7 +614,7 @@ func extractBody(response *http.Response, object runtime.Object) (string, error)
if err != nil {
return string(body), err
}
err = codec.DecodeInto(body, object)
err = runtime.DecodeInto(codec, body, object)
return string(body), err
}

Expand Down Expand Up @@ -1510,7 +1510,7 @@ func TestConnectResponderObject(t *testing.T) {
if connectStorage.receivedID != itemID {
t.Errorf("Unexpected item id. Expected: %s. Actual: %s.", itemID, connectStorage.receivedID)
}
obj, err := codec.Decode(body)
obj, err := runtime.Decode(codec, body)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1551,7 +1551,7 @@ func TestConnectResponderError(t *testing.T) {
if connectStorage.receivedID != itemID {
t.Errorf("Unexpected item id. Expected: %s. Actual: %s.", itemID, connectStorage.receivedID)
}
obj, err := codec.Decode(body)
obj, err := runtime.Decode(codec, body)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1721,7 +1721,7 @@ func TestDeleteWithOptions(t *testing.T) {
item := &api.DeleteOptions{
GracePeriodSeconds: &grace,
}
body, err := codec.Encode(item)
body, err := runtime.Encode(codec, item)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
Expand Down Expand Up @@ -1785,7 +1785,7 @@ func TestLegacyDeleteIgnoresOptions(t *testing.T) {
defer server.Close()

item := api.NewDeleteOptions(300)
body, err := codec.Encode(item)
body, err := runtime.Encode(codec, item)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
Expand Down Expand Up @@ -1938,7 +1938,7 @@ func TestUpdate(t *testing.T) {
},
Other: "bar",
}
body, err := codec.Encode(item)
body, err := runtime.Encode(codec, item)
if err != nil {
// The following cases will fail, so die now
t.Fatalf("unexpected error: %v", err)
Expand Down Expand Up @@ -1975,7 +1975,7 @@ func TestUpdateInvokesAdmissionControl(t *testing.T) {
},
Other: "bar",
}
body, err := codec.Encode(item)
body, err := runtime.Encode(codec, item)
if err != nil {
// The following cases will fail, so die now
t.Fatalf("unexpected error: %v", err)
Expand Down Expand Up @@ -2004,7 +2004,7 @@ func TestUpdateRequiresMatchingName(t *testing.T) {
item := &apiservertesting.Simple{
Other: "bar",
}
body, err := codec.Encode(item)
body, err := runtime.Encode(codec, item)
if err != nil {
// The following cases will fail, so die now
t.Fatalf("unexpected error: %v", err)
Expand Down Expand Up @@ -2036,7 +2036,7 @@ func TestUpdateAllowsMissingNamespace(t *testing.T) {
},
Other: "bar",
}
body, err := codec.Encode(item)
body, err := runtime.Encode(codec, item)
if err != nil {
// The following cases will fail, so die now
t.Fatalf("unexpected error: %v", err)
Expand Down Expand Up @@ -2074,7 +2074,7 @@ func TestUpdateAllowsMismatchedNamespaceOnError(t *testing.T) {
},
Other: "bar",
}
body, err := codec.Encode(item)
body, err := runtime.Encode(codec, item)
if err != nil {
// The following cases will fail, so die now
t.Fatalf("unexpected error: %v", err)
Expand Down Expand Up @@ -2111,7 +2111,7 @@ func TestUpdatePreventsMismatchedNamespace(t *testing.T) {
},
Other: "bar",
}
body, err := codec.Encode(item)
body, err := runtime.Encode(codec, item)
if err != nil {
// The following cases will fail, so die now
t.Fatalf("unexpected error: %v", err)
Expand Down Expand Up @@ -2146,7 +2146,7 @@ func TestUpdateMissing(t *testing.T) {
},
Other: "bar",
}
body, err := codec.Encode(item)
body, err := runtime.Encode(codec, item)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
Expand Down Expand Up @@ -2175,7 +2175,7 @@ func TestCreateNotFound(t *testing.T) {
client := http.Client{}

simple := &apiservertesting.Simple{Other: "foo"}
data, err := codec.Encode(simple)
data, err := runtime.Encode(codec, simple)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
Expand All @@ -2201,7 +2201,7 @@ func TestCreateChecksDecode(t *testing.T) {
client := http.Client{}

simple := &api.Pod{}
data, err := codec.Encode(simple)
data, err := runtime.Encode(codec, simple)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
Expand Down Expand Up @@ -2391,7 +2391,7 @@ func TestCreateWithName(t *testing.T) {
client := http.Client{}

simple := &apiservertesting.Simple{Other: "foo"}
data, err := codec.Encode(simple)
data, err := runtime.Encode(codec, simple)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
Expand All @@ -2418,7 +2418,7 @@ func TestUpdateChecksDecode(t *testing.T) {
client := http.Client{}

simple := &api.Pod{}
data, err := codec.Encode(simple)
data, err := runtime.Encode(codec, simple)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
Expand Down Expand Up @@ -2494,7 +2494,7 @@ func TestCreate(t *testing.T) {
simple := &apiservertesting.Simple{
Other: "bar",
}
data, err := codec.Encode(simple)
data, err := runtime.Encode(codec, simple)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
Expand Down Expand Up @@ -2553,7 +2553,7 @@ func TestCreateInNamespace(t *testing.T) {
simple := &apiservertesting.Simple{
Other: "bar",
}
data, err := codec.Encode(simple)
data, err := runtime.Encode(codec, simple)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
Expand Down Expand Up @@ -2612,7 +2612,7 @@ func TestCreateInvokesAdmissionControl(t *testing.T) {
simple := &apiservertesting.Simple{
Other: "bar",
}
data, err := codec.Encode(simple)
data, err := runtime.Encode(codec, simple)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
Expand Down Expand Up @@ -2740,7 +2740,7 @@ func TestCreateTimeout(t *testing.T) {
defer server.Close()

simple := &apiservertesting.Simple{Other: "foo"}
data, err := codec.Encode(simple)
data, err := runtime.Encode(codec, simple)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
Expand Down Expand Up @@ -2832,7 +2832,7 @@ func TestCreateChecksAPIVersion(t *testing.T) {

simple := &apiservertesting.Simple{}
//using newCodec and send the request to testVersion URL shall cause a discrepancy in apiVersion
data, err := newCodec.Encode(simple)
data, err := runtime.Encode(newCodec, simple)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
Expand Down Expand Up @@ -2862,7 +2862,7 @@ func TestCreateDefaultsAPIVersion(t *testing.T) {
client := http.Client{}

simple := &apiservertesting.Simple{}
data, err := codec.Encode(simple)
data, err := runtime.Encode(codec, simple)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
Expand Down Expand Up @@ -2897,7 +2897,7 @@ func TestUpdateChecksAPIVersion(t *testing.T) {
client := http.Client{}

simple := &apiservertesting.Simple{ObjectMeta: api.ObjectMeta{Name: "bar"}}
data, err := newCodec.Encode(simple)
data, err := runtime.Encode(newCodec, simple)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
Expand Down
Loading

0 comments on commit 266ab4a

Please sign in to comment.