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:
@@ -0,0 +1,46 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
|
||||
)
|
||||
|
||||
// TestCompletion_AllShells smoke-tests cobra's auto-registered completion
|
||||
// command. The output is shell-specific bytecode/script; the test just
|
||||
// asserts each shell produces a non-trivially-sized script and references
|
||||
// the binary name. Guards against future cobra bumps silently breaking
|
||||
// completion for one shell.
|
||||
func TestCompletion_AllShells(t *testing.T) {
|
||||
cases := []struct {
|
||||
shell string
|
||||
mustContain string // signature byte sequence specific to the shell
|
||||
minSizeBytes int
|
||||
}{
|
||||
{"bash", "bash completion", 1024},
|
||||
{"zsh", "#compdef", 1024},
|
||||
{"fish", "complete -c weknora", 1024},
|
||||
{"powershell", "Register-ArgumentCompleter", 1024},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.shell, func(t *testing.T) {
|
||||
cmd := NewRootCmd(&cmdutil.Factory{})
|
||||
var buf bytes.Buffer
|
||||
cmd.SetOut(&buf)
|
||||
cmd.SetErr(&buf)
|
||||
cmd.SetArgs([]string{"completion", tc.shell})
|
||||
if err := cmd.Execute(); err != nil {
|
||||
t.Fatalf("completion %s: %v", tc.shell, err)
|
||||
}
|
||||
if buf.Len() < tc.minSizeBytes {
|
||||
t.Errorf("%s script suspiciously short: %d bytes", tc.shell, buf.Len())
|
||||
}
|
||||
if !strings.Contains(buf.String(), tc.mustContain) {
|
||||
t.Errorf("%s script missing signature %q (first 200 bytes: %q)",
|
||||
tc.shell, tc.mustContain, buf.String()[:min(200, buf.Len())])
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user