MCPcopy
hub / github.com/github/git-sizer / TestScannerAlwaysFlushes

Function TestScannerAlwaysFlushes

internal/pipe/pipeline_test.go:493–539  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

491}
492
493func TestScannerAlwaysFlushes(t *testing.T) {
494 t.Parallel()
495 ctx := context.Background()
496
497 var length int64
498
499 p := pipe.New()
500 // Print the numbers from 1 to 20 (generated from scratch):
501 p.Add(
502 pipe.IgnoreError(
503 seqFunction(20),
504 pipe.IsPipeError,
505 ),
506 // Pass the numbers through up to 7, then exit with an
507 // ignored error:
508 pipe.IgnoreError(
509 pipe.LinewiseFunction(
510 "error-after-7",
511 func(_ context.Context, _ pipe.Env, line []byte, w *bufio.Writer) error {
512 fmt.Fprintf(w, "%s\n", line)
513 if string(line) == "7" {
514 return errors.New("ignore")
515 }
516 return nil
517 },
518 ),
519 func(err error) bool {
520 return err.Error() == "ignore"
521 },
522 ),
523 // Read the numbers and add them into the sum:
524 pipe.Function(
525 "compute-length",
526 func(_ context.Context, _ pipe.Env, stdin io.Reader, _ io.Writer) error {
527 var err error
528 length, err = io.Copy(io.Discard, stdin)
529 return err
530 },
531 ),
532 )
533
534 err := p.Run(ctx)
535 assert.NoError(t, err)
536 // Make sure that all of the bytes emitted before the second
537 // stage's error were received by the third stage:
538 assert.EqualValues(t, 14, length)
539}
540
541func TestScannerFinishEarly(t *testing.T) {
542 t.Parallel()

Callers

nothing calls this directly

Calls 7

NewFunction · 0.92
IgnoreErrorFunction · 0.92
LinewiseFunctionFunction · 0.92
FunctionFunction · 0.92
seqFunctionFunction · 0.85
RunMethod · 0.80
AddMethod · 0.65

Tested by

no test coverage detected