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

Function TestLoggingProcessAdapter

pkg/logging/logging_test.go:91–143  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

89}
90
91func TestLoggingProcessAdapter(t *testing.T) {
92 // Will process a normal String to stdout and a bigger one to stderr
93 normalString := generateRandomString(1024)
94
95 // Generate 64KB of random text of bufio MaxScanTokenSize
96 // https://github.com/containerd/nerdctl/issues/3343
97 hugeString := generateRandomString(bufio.MaxScanTokenSize)
98
99 // Prepare mock driver and logging config
100 driver := &MockDriver{}
101 stdoutBuffer := bytes.NewBufferString(normalString)
102 stderrBuffer := bytes.NewBufferString(hugeString)
103 config := &logging.Config{
104 Stdout: stdoutBuffer,
105 Stderr: stderrBuffer,
106 }
107
108 // Execute the logging process adapter
109 ctx, cancel := context.WithCancel(context.Background())
110 defer cancel()
111
112 var getContainerWaitMock ContainerWaitFunc = func(ctx context.Context, address string, config *logging.Config, outputSeen func() bool) (<-chan containerd.ExitStatus, error) {
113 exitChan := make(chan containerd.ExitStatus, 1)
114 time.Sleep(50 * time.Millisecond)
115 exitChan <- containerd.ExitStatus{}
116 return exitChan, nil
117 }
118
119 err := loggingProcessAdapter(ctx, driver, "testDataStore", "", getContainerWaitMock, config)
120 if err != nil {
121 t.Fatal(err)
122 }
123
124 // let bufio read the buffer
125 time.Sleep(50 * time.Millisecond)
126
127 // Verify that the driver methods were called
128 if !driver.processed {
129 t.Fatal("process should be processed")
130 }
131
132 // Verify that the driver received the expected data
133 stdout := strings.Join(driver.receivedStdout, "\n")
134 stderr := strings.Join(driver.receivedStderr, "\n")
135
136 if stdout != normalString {
137 t.Fatalf("stdout is %s, expected %s", stdout, normalString)
138 }
139
140 if stderr != hugeString {
141 t.Fatalf("stderr is %s, expected %s", stderr, hugeString)
142 }
143}
144
145// TestLoggingProcessAdapterTrailingChunk verifies that the logger forwards all
146// of the container's output, including a final chunk that has no trailing

Callers

nothing calls this directly

Calls 3

generateRandomStringFunction · 0.85
loggingProcessAdapterFunction · 0.85
BackgroundMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…