MCPcopy Create free account
hub / github.com/containerd/nerdctl / TestRunWithLogBinary

Function TestRunWithLogBinary

cmd/nerdctl/container/container_run_test.go:531–634  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

529}
530
531func TestRunWithLogBinary(t *testing.T) {
532 testCase := nerdtest.Setup()
533 testCase.Require = require.All(
534 nerdtest.Build,
535 require.Not(require.Windows),
536 require.Not(nerdtest.Docker),
537 )
538
539 var dockerfile = `
540FROM ` + testutil.GolangImage + ` as builder
541WORKDIR /go/src/
542RUN mkdir -p logger
543WORKDIR /go/src/logger
544RUN echo '\
545 package main \n\
546 \n\
547 import ( \n\
548 "bufio" \n\
549 "context" \n\
550 "fmt" \n\
551 "io" \n\
552 "os" \n\
553 "path/filepath" \n\
554 "sync" \n\
555 \n\
556 "github.com/containerd/containerd/v2/core/runtime/v2/logging"\n\
557 )\n\
558
559 func main() {\n\
560 logging.Run(log)\n\
561 }\n\
562
563 func log(ctx context.Context, config *logging.Config, ready func() error) error {\n\
564 var wg sync.WaitGroup \n\
565 wg.Add(2) \n\
566 // forward both stdout and stderr to temp files \n\
567 go copy(&wg, config.Stdout, config.ID, "stdout") \n\
568 go copy(&wg, config.Stderr, config.ID, "stderr") \n\
569
570 // signal that we are ready and setup for the container to be started \n\
571 if err := ready(); err != nil { \n\
572 return err \n\
573 } \n\
574 wg.Wait() \n\
575 return nil \n\
576 }\n\
577 \n\
578 func copy(wg *sync.WaitGroup, r io.Reader, id string, kind string) { \n\
579 f, _ := os.Create(filepath.Join(os.TempDir(), fmt.Sprintf("%s_%s.log", id, kind))) \n\
580 defer f.Close() \n\
581 defer wg.Done() \n\
582 s := bufio.NewScanner(r) \n\
583 for s.Scan() { \n\
584 f.WriteString(s.Text()) \n\
585 } \n\
586 }\n' >> main.go
587
588

Callers

nothing calls this directly

Calls 11

SetupFunction · 0.92
AssertMethod · 0.80
SaveMethod · 0.65
TempMethod · 0.65
EnsureMethod · 0.65
PathMethod · 0.65
AnyhowMethod · 0.65
IdentifierMethod · 0.65
CommandMethod · 0.65
TempDirMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…