mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-12-11 05:51:57 +01:00
af9e7d8e9e
(cherry picked from commit2555e315f7
) (cherry picked from commit51b9c9092e
) [CLI] implement forgejo-cli (squash) support initDB (cherry picked from commit5c31ae602a
) (cherry picked from commitbbf76489a7
) Conflicts: because ofd0dbe52e76
upgrade to https://pkg.go.dev/github.com/urfave/cli/v2 (cherry picked from commitb6c1bcc008
)
39 lines
951 B
Go
39 lines
951 B
Go
// 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/v2"
|
|
)
|
|
|
|
func cmdForgejoCaptureOutput(t *testing.T, args []string, stdin ...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.ContextSetNoInit(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
|
|
}
|