MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / TestPushCmd_FormatJSON

Function TestPushCmd_FormatJSON

cmd/pad/cmd_push_test.go:71–98  ·  view source on GitHub ↗

TestPushCmd_FormatJSON covers a defect: --format json was silently ignored — the RunE hardcoded plain text regardless of formatFlag. Mirrors runCreateWatch's formatFlag == "json" branch (cmd_watch.go) and asserts the full PushResult shape (ref, workspace, pushed, message), not just that SOME JSON ca

(t *testing.T)

Source from the content-addressed store, hash-verified

69// PushResult shape (ref, workspace, pushed, message), not just that
70// SOME JSON came out.
71func TestPushCmd_FormatJSON(t *testing.T) {
72 setupPushTest(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
73 w.WriteHeader(http.StatusOK)
74 _ = json.NewEncoder(w).Encode(map[string]any{
75 "ref": "TASK-5", "workspace": "demo", "pushed": true, "message": "triage this",
76 })
77 }))
78 prevFormat := formatFlag
79 formatFlag = "json"
80 defer func() { formatFlag = prevFormat }()
81
82 cmd := pushCmd()
83 cmd.SetArgs([]string{"TASK-5", "-m", "triage this"})
84
85 var execErr error
86 out := captureStdout(t, func() { execErr = cmd.Execute() })
87 if execErr != nil {
88 t.Fatalf("execute push: %v", execErr)
89 }
90
91 var result PushResultForTest
92 if err := json.Unmarshal([]byte(out), &result); err != nil {
93 t.Fatalf("output is not valid JSON: %v\noutput: %s", err, out)
94 }
95 if result.Ref != "TASK-5" || result.Workspace != "demo" || !result.Pushed || result.Message != "triage this" {
96 t.Fatalf("unexpected JSON result: %+v", result)
97 }
98}
99
100// PushResultForTest mirrors cli.PushResult's wire shape — cmd/pad
101// doesn't import internal/cli's type back out for a test-local decode,

Callers

nothing calls this directly

Calls 6

setupPushTestFunction · 0.85
pushCmdFunction · 0.85
captureStdoutFunction · 0.85
FatalfMethod · 0.80
EncodeMethod · 0.65
WriteHeaderMethod · 0.45

Tested by

no test coverage detected