feat(cli): api --input + completion smoke
api (3-11):
- `--input <file>` reads the request body from disk; `--input -` reads
from stdin. Matches gh CLI canonical naming verified against the gh
manual ("The file to use as body for the HTTP request — use \"-\" to
read from standard input"). `--data` / `--input` are mutually
exclusive.
- Options.StdinReader (defaults to iostreams.IO.In) for test injection.
completion (3-13 smoke only — release-artifact ship deferred to release
milestone):
- Smoke test asserts cobra's auto-registered bash/zsh/fish/powershell
scripts produce non-trivially-sized output with the per-shell
signature (#compdef / complete -c weknora / etc.). Guards against
cobra bumps silently breaking completion for one shell.
3-14 doctor --no-cache: already implemented (factory.go:297) with
TestDoctor_NoCache_BypassesCache covering it — verified, no change
needed.
Roadmap: 3-11, 3-13 (smoke), 3-14 (verified).
This commit is contained in:
+26
-3
@@ -117,7 +117,9 @@ func TestAPI_PostWithData(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPI_DataFile(t *testing.T) {
|
||||
// TestAPI_InputFile verifies --input <file> reads the request body from
|
||||
// disk. gh CLI parity (verified against gh manual: `--input <file>`).
|
||||
func TestAPI_InputFile(t *testing.T) {
|
||||
_, _ = iostreams.SetForTest(t)
|
||||
tmp := filepath.Join(t.TempDir(), "body.json")
|
||||
payload := `{"k":"from-file"}`
|
||||
@@ -131,12 +133,33 @@ func TestAPI_DataFile(t *testing.T) {
|
||||
})
|
||||
defer stop()
|
||||
|
||||
opts := &Options{DataFile: tmp}
|
||||
opts := &Options{Input: tmp}
|
||||
if err := runAPI(context.Background(), opts, cli, "POST", "/api/v1/x"); err != nil {
|
||||
t.Fatalf("runAPI: %v", err)
|
||||
}
|
||||
if string(seenBody) != payload {
|
||||
t.Errorf("body from --data-file: got %q, want %q", seenBody, payload)
|
||||
t.Errorf("body from --input: got %q, want %q", seenBody, payload)
|
||||
}
|
||||
}
|
||||
|
||||
// TestAPI_InputDash_Stdin verifies the gh-style "--input -" form: the
|
||||
// payload comes from opts.StdinReader (production-default iostreams.IO.In).
|
||||
func TestAPI_InputDash_Stdin(t *testing.T) {
|
||||
_, _ = iostreams.SetForTest(t)
|
||||
var seenBody []byte
|
||||
cli, stop := newTestClient(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
seenBody, _ = io.ReadAll(r.Body)
|
||||
_, _ = w.Write([]byte(`{}`))
|
||||
})
|
||||
defer stop()
|
||||
|
||||
payload := `{"k":"from-stdin"}`
|
||||
opts := &Options{Input: "-", StdinReader: strings.NewReader(payload)}
|
||||
if err := runAPI(context.Background(), opts, cli, "POST", "/api/v1/x"); err != nil {
|
||||
t.Fatalf("runAPI: %v", err)
|
||||
}
|
||||
if string(seenBody) != payload {
|
||||
t.Errorf("body from --input -: got %q, want %q", seenBody, payload)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user