MCPcopy
hub / github.com/kopia/kopia / Run

Method Run

tests/testenv/cli_test_env.go:295–344  ·  view source on GitHub ↗

Run executes kopia with given arguments and returns the output lines.

(tb testing.TB, expectedError bool, args ...string)

Source from the content-addressed store, hash-verified

293
294// Run executes kopia with given arguments and returns the output lines.
295func (e *CLITest) Run(tb testing.TB, expectedError bool, args ...string) (stdout, stderr []string, err error) {
296 tb.Helper()
297
298 args = e.cmdArgs(args)
299 outputPrefix, logOutput := e.getLogOutputPrefix()
300 tb.Logf("%vrunning 'kopia %v' with %v", outputPrefix, strings.Join(args, " "), e.Environment)
301
302 timer := timetrack.StartTimer()
303
304 stdoutReader, stderrReader, wait, _ := e.Runner.Start(tb, e.RunContext, args, e.Environment)
305
306 var wg sync.WaitGroup
307
308 wg.Go(func() {
309 scanner := bufio.NewScanner(stdoutReader)
310 for scanner.Scan() {
311 if logOutput {
312 tb.Logf("[%vstdout] %v", outputPrefix, scanner.Text())
313 }
314
315 stdout = append(stdout, scanner.Text())
316 }
317 })
318
319 wg.Go(func() {
320 scanner := bufio.NewScanner(stderrReader)
321 for scanner.Scan() {
322 if logOutput {
323 tb.Logf("[%vstderr] %v", outputPrefix, scanner.Text())
324 }
325
326 stderr = append(stderr, scanner.Text())
327 }
328 })
329
330 wg.Wait()
331
332 gotErr := wait()
333
334 if expectedError {
335 require.Error(tb, gotErr, "unexpected success when running 'kopia %v' (stdout:\n%v\nstderr:\n%v", strings.Join(args, " "), strings.Join(stdout, "\n"), strings.Join(stderr, "\n"))
336 } else {
337 require.NoError(tb, gotErr, "unexpected error when running 'kopia %v' (stdout:\n%v\nstderr:\n%v", strings.Join(args, " "), strings.Join(stdout, "\n"), strings.Join(stderr, "\n"))
338 }
339
340 //nolint:forbidigo
341 tb.Logf("%vfinished in %v: 'kopia %v'", outputPrefix, timer.Elapsed().Milliseconds(), strings.Join(args, " "))
342
343 return stdout, stderr, gotErr
344}

Callers 7

TestSnapshotVerifyFunction · 0.95
TestContentVerifyMethod · 0.95
TestLoggingFlagsFunction · 0.95
testPermissionsFunction · 0.95
RunAndExpectSuccessMethod · 0.95
RunAndExpectFailureMethod · 0.95

Calls 9

cmdArgsMethod · 0.95
getLogOutputPrefixMethod · 0.95
StartTimerFunction · 0.92
HelperMethod · 0.80
LogfMethod · 0.80
ElapsedMethod · 0.80
StartMethod · 0.65
WaitMethod · 0.65
ErrorMethod · 0.65

Tested by 4

TestSnapshotVerifyFunction · 0.76
TestContentVerifyMethod · 0.76
TestLoggingFlagsFunction · 0.76
testPermissionsFunction · 0.76