NewCLITest creates a new instance of *CLITest.
(tb testing.TB, repoCreateFlags []string, runner CLIRunner)
| 67 | |
| 68 | // NewCLITest creates a new instance of *CLITest. |
| 69 | func NewCLITest(tb testing.TB, repoCreateFlags []string, runner CLIRunner) *CLITest { |
| 70 | tb.Helper() |
| 71 | configDir := testutil.TempDirectory(tb) |
| 72 | |
| 73 | // unset global environment variable that may interfere with the test |
| 74 | os.Unsetenv("KOPIA_METRICS_PUSH_ADDR") |
| 75 | |
| 76 | fixedArgs := []string{ |
| 77 | // use per-test config file, to avoid clobbering current user's setup. |
| 78 | "--config-file", filepath.Join(configDir, ".kopia.config"), |
| 79 | } |
| 80 | |
| 81 | // disable the use of keyring |
| 82 | switch runtime.GOOS { |
| 83 | case "darwin": |
| 84 | fixedArgs = append(fixedArgs, "--no-use-keychain") |
| 85 | case "windows": |
| 86 | fixedArgs = append(fixedArgs, "--no-use-credential-manager") |
| 87 | case "linux": |
| 88 | fixedArgs = append(fixedArgs, "--no-use-keyring") |
| 89 | } |
| 90 | |
| 91 | var formatFlags []string |
| 92 | |
| 93 | formatFlags = append(formatFlags, repoCreateFlags...) |
| 94 | |
| 95 | if testutil.ShouldReduceTestComplexity() { |
| 96 | formatFlags = append(formatFlags, |
| 97 | "--encryption", "CHACHA20-POLY1305-HMAC-SHA256", |
| 98 | "--block-hash", "BLAKE2S-256") |
| 99 | } |
| 100 | |
| 101 | return &CLITest{ |
| 102 | RunContext: testsender.CaptureMessages(testlogging.Context(tb)), |
| 103 | startTime: clock.Now(), |
| 104 | RepoDir: testutil.TempDirectory(tb), |
| 105 | ConfigDir: configDir, |
| 106 | fixedArgs: fixedArgs, |
| 107 | DefaultRepositoryCreateFlags: formatFlags, |
| 108 | Environment: map[string]string{ |
| 109 | "KOPIA_PASSWORD": TestRepoPassword, |
| 110 | }, |
| 111 | Runner: runner, |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | // RunAndExpectSuccess runs the given command, expects it to succeed and returns its output lines. |
| 116 | func (e *CLITest) RunAndExpectSuccess(tb testing.TB, args ...string) []string { |