MCPcopy Index your code
hub / github.com/github/git-sizer / TestScannerFinishEarly

Function TestScannerFinishEarly

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

Source from the content-addressed store, hash-verified

539}
540
541func TestScannerFinishEarly(t *testing.T) {
542 t.Parallel()
543 ctx := context.Background()
544
545 var length int64
546
547 p := pipe.New()
548 p.Add(
549 // Print the numbers from 1 to 20 (generated from scratch):
550 seqFunction(20),
551
552 // Pass the numbers through up to 7, then exit with an ignored
553 // error:
554 pipe.LinewiseFunction(
555 "finish-after-7",
556 func(_ context.Context, _ pipe.Env, line []byte, w *bufio.Writer) error {
557 fmt.Fprintf(w, "%s\n", line)
558 if string(line) == "7" {
559 return pipe.FinishEarly
560 }
561 return nil
562 },
563 ),
564
565 // Read the numbers and add them into the sum:
566 pipe.Function(
567 "compute-length",
568 func(_ context.Context, _ pipe.Env, stdin io.Reader, _ io.Writer) error {
569 var err error
570 length, err = io.Copy(io.Discard, stdin)
571 return err
572 },
573 ),
574 )
575
576 err := p.Run(ctx)
577 assert.NoError(t, err)
578 // Make sure that all of the bytes emitted before the second
579 // stage's error were received by the third stage:
580 assert.EqualValues(t, 14, length)
581}
582
583func TestPrintln(t *testing.T) {
584 t.Parallel()

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected