(t *testing.T)
| 67 | } |
| 68 | |
| 69 | func TestPrintJSON(t *testing.T) { |
| 70 | type payload struct { |
| 71 | Name string `json:"name"` |
| 72 | Value int `json:"value"` |
| 73 | } |
| 74 | |
| 75 | got := captureStdout(t, func() { |
| 76 | if err := printJSON(payload{Name: "test", Value: 42}); err != nil { |
| 77 | t.Fatalf("printJSON returned error: %v", err) |
| 78 | } |
| 79 | }) |
| 80 | |
| 81 | var decoded payload |
| 82 | if err := json.Unmarshal([]byte(got), &decoded); err != nil { |
| 83 | t.Fatalf("output is not valid JSON: %v\noutput: %s", err, got) |
| 84 | } |
| 85 | |
| 86 | if decoded.Name != "test" || decoded.Value != 42 { |
| 87 | t.Errorf("unexpected decoded value: %+v", decoded) |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | func TestPrintError(t *testing.T) { |
| 92 | sentinel := errors.New("something went wrong") |
nothing calls this directly
no test coverage detected