mirror of
https://github.com/kopia/kopia.git
synced 2026-03-17 21:56:14 -04:00
* 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.
48 lines
1.2 KiB
Go
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
|
|
}
|