forked from NYANDEV/forgejo
[CLI] implement forgejo-cli
(cherry picked from commit 2555e315f7561302484b15576d34c5da0d4cdb12) (cherry picked from commit 987df92935ecc03e36f1754b7cbe7a81df8f000f) (cherry picked from commit 78e7eee59ae43b0e38ff5ab4cdf7fbca33cb6789)
This commit is contained in:
parent
f9618b8896
commit
935fb85e8b
3 changed files with 200 additions and 1 deletions
39
tests/integration/cmd_forgejo_test.go
Normal file
39
tests/integration/cmd_forgejo_test.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"flag"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/cmd/forgejo"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
func cmdForgejoCaptureOutput(t *testing.T, args []string) (string, error) {
|
||||
r, w, err := os.Pipe()
|
||||
assert.NoError(t, err)
|
||||
set := flag.NewFlagSet("forgejo-cli", 0)
|
||||
assert.NoError(t, set.Parse(args))
|
||||
cliContext := cli.NewContext(&cli.App{Writer: w, ErrWriter: w}, set, nil)
|
||||
ctx := context.Background()
|
||||
ctx = forgejo.ContextSetNoInstallSignals(ctx, true)
|
||||
ctx = forgejo.ContextSetNoExit(ctx, true)
|
||||
ctx = forgejo.ContextSetStdout(ctx, w)
|
||||
ctx = forgejo.ContextSetStderr(ctx, w)
|
||||
if len(stdin) > 0 {
|
||||
ctx = forgejo.ContextSetStdin(ctx, strings.NewReader(strings.Join(stdin, "")))
|
||||
}
|
||||
err = forgejo.CmdForgejo(ctx).Run(cliContext)
|
||||
w.Close()
|
||||
var buf bytes.Buffer
|
||||
io.Copy(&buf, r)
|
||||
return buf.String(), err
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue