test: rewrite functional tests for full CLI coverage

Consolidate all tests into functional_test.go — remove duplicate
new_commands_test.go. Replace SDK-only tests with actual CLI binary
invocations. Add missing coverage for: issue list, issue view,
issue comment, issue create, issue edit title, repo view, repo list,
release view, --json flag on issue list/view and pr list.
All tests now use -R flag consistently.

35 pass, 0 fail, 3 expected skips (pr view/diff need PRs, clone needs auth).
This commit is contained in:
sid 2026-03-21 22:12:20 -06:00
parent 95da06c003
commit 7c0dcc8696
2 changed files with 892 additions and 609 deletions

View file

@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"code.gitea.io/sdk/gitea"
@ -295,3 +296,39 @@ func (env *TestEnv) RunCLI(args ...string) *CLIResult {
return result
}
// runCLIWithStdin executes the CLI binary with the given args and pipes input to stdin.
func (env *TestEnv) runCLIWithStdin(input string, args ...string) *CLIResult {
cmd := exec.Command(env.GetBinaryPath(), args...)
cmd.Env = os.Environ()
cmd.Stdin = strings.NewReader(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()
}
}
result := &CLIResult{
Stdout: stdout.String(),
Stderr: stderr.String(),
ExitCode: exitCode,
}
env.T.Logf("Command: %s %v", env.GetBinaryPath(), args)
env.T.Logf("Exit code: %d", exitCode)
if stdout.Len() > 0 {
env.T.Logf("Stdout:\n%s", result.Stdout)
}
if stderr.Len() > 0 {
env.T.Logf("Stderr:\n%s", result.Stderr)
}
return result
}

File diff suppressed because it is too large Load diff