MCPcopy
hub / github.com/google/cadvisor / expectManagerWithContainersV2

Function expectManagerWithContainersV2

lib/manager/manager_test.go:383–426  ·  view source on GitHub ↗

Expect a manager with the specified containers and query. Returns the manager, map of ContainerInfo objects, and map of MockContainerHandler objects.}

(containers []string, query *info.ContainerInfoRequest, t *testing.T)

Source from the content-addressed store, hash-verified

381// Expect a manager with the specified containers and query. Returns the manager, map of ContainerInfo objects,
382// and map of MockContainerHandler objects.}
383func expectManagerWithContainersV2(containers []string, query *info.ContainerInfoRequest, t *testing.T) (*manager, map[string]*info.ContainerInfo, map[string]*containertest.MockContainerHandler) {
384 infosMap := make(map[string]*info.ContainerInfo, len(containers))
385 handlerMap := make(map[string]*containertest.MockContainerHandler, len(containers))
386
387 for _, container := range containers {
388 infosMap[container] = itest.GenerateRandomContainerInfo(container, 4, query, 1*time.Second)
389 }
390
391 memoryCache := memory.New(time.Duration(query.NumStats)*time.Second, nil)
392 sysfs := &fakesysfs.FakeSysFs{}
393 m := createManagerAndAddContainers(
394 memoryCache,
395 sysfs,
396 containers,
397 func(h *containertest.MockContainerHandler) {
398 cinfo := infosMap[h.Name]
399 ref, err := h.ContainerReference()
400 if err != nil {
401 t.Error(err)
402 }
403
404 cInfo := info.ContainerInfo{
405 ContainerReference: ref,
406 }
407
408 for _, stat := range cinfo.Stats {
409 err = memoryCache.AddStats(&cInfo, stat)
410 if err != nil {
411 t.Error(err)
412 }
413 }
414 spec := cinfo.Spec
415
416 h.On("GetSpec").Return(
417 spec,
418 nil,
419 ).Once()
420 handlerMap[h.Name] = h
421 },
422 t,
423 )
424
425 return m, infosMap, handlerMap
426}
427
428func TestGetContainerInfoV2(t *testing.T) {
429 containers := []string{

Callers 1

TestGetContainerInfoV2Function · 0.85

Calls 5

NewFunction · 0.92
ContainerReferenceMethod · 0.65
AddStatsMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…