- Add tests for shell completion generation in completion_test.go - Add tests for root command execution and flags in root_test.go - Expand config tests for temperature, timeout, and log level getters - Add APIError unwrap test in errors_test.go - Add WithContext tests in logger_test.go - Stage test output artifact in .output.txt
43 lines
691 B
Go
43 lines
691 B
Go
package cmd
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func TestCompletionCmd(t *testing.T) {
|
|
tests := []struct {
|
|
shell string
|
|
}{
|
|
{"bash"},
|
|
{"zsh"},
|
|
{"fish"},
|
|
{"powershell"},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.shell, func(t *testing.T) {
|
|
oldStdout := os.Stdout
|
|
defer func() { os.Stdout = oldStdout }()
|
|
r, w, err := os.Pipe()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
os.Stdout = w
|
|
defer w.Close()
|
|
cmd := &cobra.Command{}
|
|
completionCmd.Run(cmd, []string{tt.shell})
|
|
w.Close()
|
|
b, err := io.ReadAll(r)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(b) == 0 {
|
|
t.Error("expected non-empty completion script")
|
|
}
|
|
})
|
|
}
|
|
}
|