Fix test for deprecated JSON funcs.

This commit is contained in:
Craig Jackson 2013-10-27 11:56:52 -07:00
parent 9d9a930c1e
commit 4c1b03581a
1 changed files with 27 additions and 8 deletions

View File

@ -23,18 +23,10 @@ func TestJSON(t *testing.T) {
expect.A = 1 expect.A = 1
expect.B = "hello" expect.B = "hello"
if err := WriteJSON(wc, &expect); err != nil {
t.Fatal("write", err)
}
if err := wc.WriteJSON(&expect); err != nil { if err := wc.WriteJSON(&expect); err != nil {
t.Fatal("write", err) t.Fatal("write", err)
} }
if err := ReadJSON(rc, &expect); err != nil {
t.Fatal("read", err)
}
if err := rc.ReadJSON(&actual); err != nil { if err := rc.ReadJSON(&actual); err != nil {
t.Fatal("read", err) t.Fatal("read", err)
} }
@ -43,3 +35,30 @@ func TestJSON(t *testing.T) {
t.Fatal("equal", actual, expect) t.Fatal("equal", actual, expect)
} }
} }
func TestDeprecatedJSON(t *testing.T) {
var buf bytes.Buffer
c := fakeNetConn{&buf, &buf}
wc := newConn(c, true, 1024, 1024)
rc := newConn(c, false, 1024, 1024)
var actual, expect struct {
A int
B string
}
expect.A = 1
expect.B = "hello"
if err := WriteJSON(wc, &expect); err != nil {
t.Fatal("write", err)
}
if err := ReadJSON(rc, &actual); err != nil {
t.Fatal("read", err)
}
if !reflect.DeepEqual(&actual, &expect) {
t.Fatal("equal", actual, expect)
}
}