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

Function expectManagerWithSubContainers

lib/manager/manager_test.go:338–379  ·  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

336// Expect a manager with the specified containers and query. Returns the manager, map of ContainerInfo objects,
337// and map of MockContainerHandler objects.}
338func expectManagerWithSubContainers(containers []string, query *info.ContainerInfoRequest, t *testing.T) (*manager, map[string]*info.ContainerInfo, map[string]*containertest.MockContainerHandler) {
339 infosMap := make(map[string]*info.ContainerInfo, len(containers))
340 handlerMap := make(map[string]*containertest.MockContainerHandler, len(containers))
341
342 for _, container := range containers {
343 infosMap[container] = itest.GenerateRandomContainerInfo(container, 4, query, 1*time.Second)
344 }
345
346 memoryCache := memory.New(time.Duration(query.NumStats)*time.Second, nil)
347 sysfs := &fakesysfs.FakeSysFs{}
348 m := createManagerAndAddSubContainers(
349 memoryCache,
350 sysfs,
351 containers,
352 func(h *containertest.MockContainerHandler) {
353 cinfo := infosMap[h.Name]
354 ref, err := h.ContainerReference()
355 if err != nil {
356 t.Error(err)
357 }
358
359 cInfo := info.ContainerInfo{
360 ContainerReference: ref,
361 }
362 for _, stat := range cinfo.Stats {
363 err = memoryCache.AddStats(&cInfo, stat)
364 if err != nil {
365 t.Error(err)
366 }
367 }
368 spec := cinfo.Spec
369 h.On("GetSpec").Return(
370 spec,
371 nil,
372 ).Once()
373 handlerMap[h.Name] = h
374 },
375 t,
376 )
377
378 return m, infosMap, handlerMap
379}
380
381// Expect a manager with the specified containers and query. Returns the manager, map of ContainerInfo objects,
382// and map of MockContainerHandler objects.}

Callers 1

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…