Files
kopia/tests/testenv/cli_inproc_runner.go
Jarek Kowalski fcd507a56d Refactored most of the CLI tests to run in-process as opposed to using sub-processes (#1059)
* cli: fixed remaining testability indirections for output and logging

* cli: added cli.RunSubcommand() which is used in testing to execute a subcommand in the same process

* tests: refactored most e2e tests to invoke kopia subcommands in-process

* Makefile: enable code coverage for cli/ and internal/

* testing: pass 'testing' tag to unit tests which uses much faster (insecure) password hashing scheme

* Makefile: push coverage from PRs again

* tests: disable buffer management to reduce memory usage on ARM

* cli: fixed misaligned atomic field on ARMHF

also temporarily fixed statup-time benign race condition when setting
default on the timeZone variable, which is the last global variable.
2021-05-11 22:26:28 -07:00

48 lines
1.2 KiB
Go

package testenv
import (
"io"
"os"
"testing"
"github.com/kopia/kopia/cli"
"github.com/kopia/kopia/internal/buf"
"github.com/kopia/kopia/internal/testlogging"
)
// CLIInProcRunner is a CLIRunner that invokes provided commands in the current process.
type CLIInProcRunner struct{}
// 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", TestRepoPassword,
}, 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") != "" {
t.Skip("not running test since it's also included in the unit tests")
}
return &CLIInProcRunner{}
}
var _ CLIRunner = (*CLIInProcRunner)(nil)
func init() {
// disable buffer management in end-to-end tests as running too many of them in parallel causes too
// much memory usage on low-end platforms.
buf.DisableBufferManagement = true
}