util.EncodeJSON proven harmful, remove it everywhere
People were misusing EncodeJSON in tests when they should be using runtime.EncodeOrDie(testapi.Codec(), obj). Removing the potential for cutting self on sharp objects.
This commit is contained in:
@@ -24,39 +24,6 @@ import (
|
||||
"gopkg.in/v1/yaml"
|
||||
)
|
||||
|
||||
type FakeTypeMeta struct {
|
||||
ID string
|
||||
}
|
||||
type FakePod struct {
|
||||
FakeTypeMeta `json:",inline" yaml:",inline"`
|
||||
Labels map[string]string
|
||||
Int int
|
||||
Str string
|
||||
}
|
||||
|
||||
func TestEncodeJSON(t *testing.T) {
|
||||
pod := FakePod{
|
||||
FakeTypeMeta: FakeTypeMeta{ID: "foo"},
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"baz": "blah",
|
||||
},
|
||||
Int: -6,
|
||||
Str: "a string",
|
||||
}
|
||||
|
||||
body := EncodeJSON(pod)
|
||||
|
||||
expectedBody, err := json.Marshal(pod)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if string(expectedBody) != body {
|
||||
t.Errorf("JSON doesn't match. Expected %s, saw %s", expectedBody, body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleCrash(t *testing.T) {
|
||||
count := 0
|
||||
expect := 10
|
||||
|
Reference in New Issue
Block a user