(t *testing.T)
| 51 | } |
| 52 | |
| 53 | func TestWriteJSON(t *testing.T) { |
| 54 | person := struct { |
| 55 | Name string |
| 56 | Age int |
| 57 | }{ |
| 58 | Name: "Alice", |
| 59 | Age: 30, |
| 60 | } |
| 61 | |
| 62 | var b bytes.Buffer |
| 63 | err := WriteJSON(&b, person) |
| 64 | if err != nil { |
| 65 | t.Fatal(err) |
| 66 | } |
| 67 | |
| 68 | expected := `{"Name":"Alice","Age":30}` |
| 69 | if b.String() != expected { |
| 70 | t.Errorf("expected to write %s but was %s", expected, b.String()) |
| 71 | } |
| 72 | } |