MCPcopy
hub / github.com/containerd/containerd / TestLongContainerLog

Function TestLongContainerLog

integration/container_log_test.go:82–138  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

80}
81
82func TestLongContainerLog(t *testing.T) {
83 testPodLogDir := t.TempDir()
84
85 t.Log("Create a sandbox with log directory")
86 sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox", "long-container-log",
87 WithPodLogDirectory(testPodLogDir),
88 )
89
90 var (
91 testImage = images.Get(images.BusyBox)
92 containerName = "test-container"
93 )
94
95 EnsureImageExists(t, testImage)
96
97 t.Log("Create a container with log path")
98 config, err := CRIConfig()
99 require.NoError(t, err)
100 maxSize := config.MaxContainerLogLineSize
101 shortLineCmd := fmt.Sprintf("i=0; while [ $i -lt %d ]; do printf %s; i=$((i+1)); done", maxSize-1, "a")
102 maxLenLineCmd := fmt.Sprintf("i=0; while [ $i -lt %d ]; do printf %s; i=$((i+1)); done", maxSize, "b")
103 longLineCmd := fmt.Sprintf("i=0; while [ $i -lt %d ]; do printf %s; i=$((i+1)); done", maxSize+1, "c")
104 cnConfig := ContainerConfig(
105 containerName,
106 testImage,
107 WithCommand("sh", "-c",
108 fmt.Sprintf("%s; echo; %s; echo; %s; echo", shortLineCmd, maxLenLineCmd, longLineCmd)),
109 WithLogPath(containerName),
110 )
111 cn, err := runtimeService.CreateContainer(sb, cnConfig, sbConfig)
112 require.NoError(t, err)
113
114 t.Log("Start the container")
115 require.NoError(t, runtimeService.StartContainer(cn))
116
117 t.Log("Wait for container to finish running")
118 require.NoError(t, Eventually(func() (bool, error) {
119 s, err := runtimeService.ContainerStatus(cn)
120 if err != nil {
121 return false, err
122 }
123 if s.GetState() == runtime.ContainerState_CONTAINER_EXITED {
124 return true, nil
125 }
126 return false, nil
127 }, time.Second, 30*time.Second))
128
129 t.Log("Check container log")
130 content, err := os.ReadFile(filepath.Join(testPodLogDir, containerName))
131 assert.NoError(t, err)
132 checkContainerLog(t, string(content), []string{
133 fmt.Sprintf("%s %s %s", runtime.Stdout, runtime.LogTagFull, strings.Repeat("a", maxSize-1)),
134 fmt.Sprintf("%s %s %s", runtime.Stdout, runtime.LogTagFull, strings.Repeat("b", maxSize)),
135 fmt.Sprintf("%s %s %s", runtime.Stdout, runtime.LogTagPartial, strings.Repeat("c", maxSize)),
136 fmt.Sprintf("%s %s %s", runtime.Stdout, runtime.LogTagFull, "c"),
137 })
138}
139

Callers

nothing calls this directly

Calls 15

GetFunction · 0.92
WithPodLogDirectoryFunction · 0.85
EnsureImageExistsFunction · 0.85
CRIConfigFunction · 0.85
ContainerConfigFunction · 0.85
WithCommandFunction · 0.85
WithLogPathFunction · 0.85
EventuallyFunction · 0.85
checkContainerLogFunction · 0.85
LogMethod · 0.80
CreateContainerMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…