mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
Add complete integration test coverage for all CLI commands with isolated sandbox environments that run on every change. Changes: - Add testutil package for sandbox test infrastructure - Add 77 integration tests covering all commands (init, sync, status, diff, backup, restore, pull, doctor, target, version, help) - Update CI workflow to run integration tests on Ubuntu and macOS - Add SKILLSHARE_CONFIG env var support for test isolation - Add mise.toml for task management - Move scripts to scripts/ directory
87 lines
1.6 KiB
Go
87 lines
1.6 KiB
Go
package testutil
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"os/exec"
|
|
)
|
|
|
|
// Result holds command execution results
|
|
type Result struct {
|
|
ExitCode int
|
|
Stdout string
|
|
Stderr string
|
|
}
|
|
|
|
// RunCLI executes the skillshare CLI with given arguments
|
|
func (sb *Sandbox) RunCLI(args ...string) *Result {
|
|
sb.T.Helper()
|
|
|
|
cmd := exec.Command(sb.BinaryPath, args...)
|
|
cmd.Env = append(os.Environ(),
|
|
"HOME="+sb.Home,
|
|
"SKILLSHARE_CONFIG="+sb.ConfigPath,
|
|
)
|
|
|
|
var stdout, stderr bytes.Buffer
|
|
cmd.Stdout = &stdout
|
|
cmd.Stderr = &stderr
|
|
|
|
err := cmd.Run()
|
|
|
|
exitCode := 0
|
|
if err != nil {
|
|
if exitErr, ok := err.(*exec.ExitError); ok {
|
|
exitCode = exitErr.ExitCode()
|
|
} else {
|
|
sb.T.Logf("failed to run CLI: %v", err)
|
|
exitCode = -1
|
|
}
|
|
}
|
|
|
|
return &Result{
|
|
ExitCode: exitCode,
|
|
Stdout: stdout.String(),
|
|
Stderr: stderr.String(),
|
|
}
|
|
}
|
|
|
|
// RunCLIWithInput executes CLI with stdin input (for interactive prompts)
|
|
func (sb *Sandbox) RunCLIWithInput(input string, args ...string) *Result {
|
|
sb.T.Helper()
|
|
|
|
cmd := exec.Command(sb.BinaryPath, args...)
|
|
cmd.Env = append(os.Environ(),
|
|
"HOME="+sb.Home,
|
|
"SKILLSHARE_CONFIG="+sb.ConfigPath,
|
|
)
|
|
cmd.Stdin = bytes.NewBufferString(input)
|
|
|
|
var stdout, stderr bytes.Buffer
|
|
cmd.Stdout = &stdout
|
|
cmd.Stderr = &stderr
|
|
|
|
err := cmd.Run()
|
|
|
|
exitCode := 0
|
|
if err != nil {
|
|
if exitErr, ok := err.(*exec.ExitError); ok {
|
|
exitCode = exitErr.ExitCode()
|
|
} else {
|
|
sb.T.Logf("failed to run CLI: %v", err)
|
|
exitCode = -1
|
|
}
|
|
}
|
|
|
|
return &Result{
|
|
ExitCode: exitCode,
|
|
Stdout: stdout.String(),
|
|
Stderr: stderr.String(),
|
|
}
|
|
}
|
|
|
|
// Output returns combined stdout and stderr
|
|
func (r *Result) Output() string {
|
|
return r.Stdout + r.Stderr
|
|
}
|