Files
kopia/tests/testenv/cli_inproc_runner.go
Jarek Kowalski 35d0f31c0d huge: replaced the use of allocated byte slices with populating gather.WriteBuffer in the repository (#1244)
This helps recycle buffers more efficiently during snapshots.
Also, improved memory tracking, enabled profiling flags and added pprof
by default.
2021-08-20 08:45:10 -07:00

45 lines
1.0 KiB
Go

package testenv
import (
"io"
"os"
"testing"
"github.com/kopia/kopia/cli"
"github.com/kopia/kopia/internal/testlogging"
)
// CLIInProcRunner is a CLIRunner that invokes provided commands in the current process.
type CLIInProcRunner struct {
RepoPassword string
}
// Start implements CLIRunner.
func (e *CLIInProcRunner) Start(t *testing.T, args []string) (stdout, stderr io.Reader, wait func() error, kill func()) {
t.Helper()
ctx := testlogging.Context(t)
a := cli.NewApp()
a.AdvancedCommands = "enabled"
return a.RunSubcommand(ctx, append([]string{
"--password", e.RepoPassword,
}, args...))
}
// NewInProcRunner returns a runner that executes CLI subcommands in the current process using cli.RunSubcommand().
func NewInProcRunner(t *testing.T) *CLIInProcRunner {
t.Helper()
if os.Getenv("KOPIA_EXE") != "" && os.Getenv("KOPIA_RUN_ALL_INTEGRATION_TESTS") == "" {
t.Skip("not running test since it's also included in the unit tests")
}
return &CLIInProcRunner{
RepoPassword: TestRepoPassword,
}
}
var _ CLIRunner = (*CLIInProcRunner)(nil)