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

Function TestFunction

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

Source from the content-addressed store, hash-verified

352}
353
354func TestFunction(t *testing.T) {
355 t.Parallel()
356 ctx := context.Background()
357
358 p := pipe.New()
359 p.Add(
360 pipe.Print("hello world"),
361 pipe.Function(
362 "farewell",
363 func(_ context.Context, _ pipe.Env, stdin io.Reader, stdout io.Writer) error {
364 buf, err := io.ReadAll(stdin)
365 if err != nil {
366 return err
367 }
368 if string(buf) != "hello world" {
369 return fmt.Errorf("expected \"hello world\"; got %q", string(buf))
370 }
371 _, err = stdout.Write([]byte("goodbye, cruel world"))
372 return err
373 },
374 ),
375 )
376
377 out, err := p.Output(ctx)
378 assert.NoError(t, err)
379 assert.EqualValues(t, "goodbye, cruel world", out)
380}
381
382func TestPipelineWithFunction(t *testing.T) {
383 t.Parallel()

Callers

nothing calls this directly

Calls 5

NewFunction · 0.92
PrintFunction · 0.92
FunctionFunction · 0.92
OutputMethod · 0.80
AddMethod · 0.65

Tested by

no test coverage detected