chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,46 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"academy/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 academy", 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