Test to verify filtering without any filter
(t *testing.T)
| 146 | |
| 147 | // Test to verify filtering without any filter |
| 148 | func TestContainerListStats(t *testing.T) { |
| 149 | var ( |
| 150 | stats []*runtime.ContainerStats |
| 151 | err error |
| 152 | ) |
| 153 | t.Logf("Create a pod config and run sandbox container") |
| 154 | sb, sbConfig := PodSandboxConfigWithCleanup(t, "running-pod", "statsls") |
| 155 | |
| 156 | pauseImage := images.Get(images.Pause) |
| 157 | EnsureImageExists(t, pauseImage) |
| 158 | |
| 159 | t.Logf("Create a container config and run containers in a pod") |
| 160 | containerConfigMap := make(map[string]*runtime.ContainerConfig) |
| 161 | for i := range 3 { |
| 162 | cName := fmt.Sprintf("container%d", i) |
| 163 | containerConfig := ContainerConfig( |
| 164 | cName, |
| 165 | pauseImage, |
| 166 | WithTestLabels(), |
| 167 | WithTestAnnotations(), |
| 168 | ) |
| 169 | cn, err := runtimeService.CreateContainer(sb, containerConfig, sbConfig) |
| 170 | require.NoError(t, err) |
| 171 | containerConfigMap[cn] = containerConfig |
| 172 | defer func() { |
| 173 | assert.NoError(t, runtimeService.RemoveContainer(cn)) |
| 174 | }() |
| 175 | require.NoError(t, runtimeService.StartContainer(cn)) |
| 176 | defer func() { |
| 177 | assert.NoError(t, runtimeService.StopContainer(cn, 10)) |
| 178 | }() |
| 179 | } |
| 180 | |
| 181 | t.Logf("Fetch all container stats") |
| 182 | require.NoError(t, Eventually(func() (bool, error) { |
| 183 | stats, err = runtimeService.ListContainerStats(&runtime.ContainerStatsFilter{}) |
| 184 | if err != nil { |
| 185 | return false, err |
| 186 | } |
| 187 | for _, s := range stats { |
| 188 | if s.GetWritableLayer().GetTimestamp() == 0 { |
| 189 | return false, nil |
| 190 | } |
| 191 | } |
| 192 | return true, nil |
| 193 | }, time.Second, 30*time.Second)) |
| 194 | |
| 195 | t.Logf("Verify all container stats") |
| 196 | for _, s := range stats { |
| 197 | testStats(t, s, containerConfigMap[s.GetAttributes().GetId()]) |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | // Test to verify filtering given a specific container ID |
| 202 | // TODO Convert the filter tests into table driven tests and unit tests |
nothing calls this directly
no test coverage detected
searching dependent graphs…