MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / TestPrintJSON

Function TestPrintJSON

internal/cli/cli_helpers_test.go:69–89  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

67}
68
69func 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
91func TestPrintError(t *testing.T) {
92 sentinel := errors.New("something went wrong")

Callers

nothing calls this directly

Calls 2

captureStdoutFunction · 0.85
printJSONFunction · 0.85

Tested by

no test coverage detected