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

Function TestHandler

lib/container/containerd/handler_test.go:47–144  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

45}
46
47func TestHandler(t *testing.T) {
48 as := assert.New(t)
49 type testCase struct {
50 client ContainerdClient
51 name string
52 machineInfoFactory info.MachineInfoFactory
53 fsInfo fs.FsInfo
54 cgroupSubsystems map[string]string
55 inHostNamespace bool
56 metadataEnvAllowList []string
57 includedMetrics container.MetricSet
58
59 hasErr bool
60 errContains string
61 checkReference *info.ContainerReference
62 checkEnvVars map[string]string
63 }
64 testContainers := make(map[string]*containers.Container)
65 testContainer := &containers.Container{
66 ID: "40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9",
67 Labels: map[string]string{"io.cri-containerd.kind": "sandbox"},
68 }
69 spec := &specs.Spec{Root: &specs.Root{Path: "/test/"}, Process: &specs.Process{Env: []string{"TEST_REGION=FRA", "TEST_ZONE=A", "HELLO=WORLD"}}}
70 testContainer.Spec, _ = typeurl.MarshalAnyToProto(spec)
71 testContainers["40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9"] = testContainer
72 for _, ts := range []testCase{
73 {
74 mockcontainerdClient(nil, nil),
75 "/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9",
76 nil,
77 nil,
78 nil,
79 false,
80 nil,
81 nil,
82 true,
83 "unable to find container \"40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9\"",
84 nil,
85 nil,
86 },
87 {
88 mockcontainerdClient(testContainers, nil),
89 "/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9",
90 &mockedMachineInfo{},
91 nil,
92 nil,
93 false,
94 nil,
95 nil,
96 false,
97 "",
98 &info.ContainerReference{
99 Id: "40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9",
100 Name: "/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9",
101 Aliases: []string{"40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9", "/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9"},
102 Namespace: k8sContainerdNamespace,
103 },
104 map[string]string{},

Callers

nothing calls this directly

Calls 5

mockcontainerdClientFunction · 0.85
ContainerReferenceMethod · 0.65
GetSpecMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…