@@ -34,8 +34,9 @@ import (
3434)
3535
3636const (
37+ testContainerSandboxID = "40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9"
3738 testContainerSandboxName = "/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9"
38- testContainerId = "c6a1aa99f14d3e57417e145b897e34961145f6b6f14216a176a34bfabbf79086"
39+ testContainerID = "c6a1aa99f14d3e57417e145b897e34961145f6b6f14216a176a34bfabbf79086"
3940 testContainerName = "/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/c6a1aa99f14d3e57417e145b897e34961145f6b6f14216a176a34bfabbf79086"
4041
4142 testLogPath = "/var/log/pods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa"
@@ -60,7 +61,7 @@ func init() {
6061
6162 testContainers = make (map [string ]* containers.Container )
6263 testContainerSandbox = & containers.Container {
63- ID : "40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9" ,
64+ ID : testContainerSandboxID ,
6465 Labels : map [string ]string {
6566 "io.cri-containerd.kind" : "sandbox" ,
6667 "io.kubernetes.container.name" : "pause" ,
@@ -69,7 +70,7 @@ func init() {
6970 "io.kubernetes.pod.uid" : "some-uid" },
7071 }
7172 testContainer = & containers.Container {
72- ID : "c6a1aa99f14d3e57417e145b897e34961145f6b6f14216a176a34bfabbf79086" ,
73+ ID : testContainerID ,
7374 Labels : map [string ]string {
7475 "io.cri-containerd.kind" : "container" ,
7576 "io.kubernetes.container.name" : "some-container" ,
@@ -80,8 +81,8 @@ func init() {
8081 spec := & specs.Spec {Root : & specs.Root {Path : "/test/" }, Process : & specs.Process {Env : []string {"TEST_REGION=FRA" , "TEST_ZONE=A" , "HELLO=WORLD" }}}
8182 testContainerSandbox .Spec , _ = typeurl .MarshalAny (spec )
8283 testContainer .Spec , _ = typeurl .MarshalAny (spec )
83- testContainers ["40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9" ] = testContainerSandbox
84- testContainers ["c6a1aa99f14d3e57417e145b897e34961145f6b6f14216a176a34bfabbf79086" ] = testContainer
84+ testContainers [testContainerSandboxID ] = testContainerSandbox
85+ testContainers [testContainerID ] = testContainer
8586
8687 testStatus = & criapi.ContainerStatus {
8788 Metadata : & criapi.ContainerMetadata {Attempt : 2 },
@@ -114,11 +115,10 @@ type fsInfoMock struct {
114115}
115116
116117func (m * fsInfoMock ) GetDirFsDevice (dir string ) (* fs.DeviceInfo , error ) {
117- if dir == m .deviceDir {
118- return m .deviceinfo , nil
119- } else {
118+ if dir != m .deviceDir {
120119 return nil , fmt .Errorf ("cannot get device for dir: %q" , dir )
121120 }
121+ return m .deviceinfo , nil
122122}
123123
124124func (m * fsInfoMock ) GetGlobalFsInfo () ([]fs.Fs , error ) {
@@ -173,21 +173,21 @@ func TestHandler(t *testing.T) {
173173 for _ , ts := range []testCase {
174174 {
175175 mockcontainerdClient (nil , nil , nil , nil , nil ),
176- "/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9" ,
176+ testContainerSandboxName ,
177177 nil ,
178178 nil ,
179179 & containerlibcontainer.CgroupSubsystems {},
180180 false ,
181181 nil ,
182182 nil ,
183183 true ,
184- "unable to find container \" 40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9 \" " ,
184+ "unable to find container \" " + testContainerSandboxID + " \" " ,
185185 nil ,
186186 nil ,
187187 },
188188 {
189189 mockcontainerdClient (testContainers , nil , nil , nil , nil ),
190- "/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9" ,
190+ testContainerSandboxName ,
191191 & mockedMachineInfo {},
192192 nil ,
193193 & containerlibcontainer.CgroupSubsystems {},
@@ -197,16 +197,16 @@ func TestHandler(t *testing.T) {
197197 false ,
198198 "" ,
199199 & info.ContainerReference {
200- Id : "40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9" ,
201- Name : "/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9" ,
202- Aliases : []string {"k8s_POD_some-pod_some-ns_some-uid_0" , "40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9" , "/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9" },
200+ Id : testContainerSandboxID ,
201+ Name : testContainerSandboxName ,
202+ Aliases : []string {"k8s_POD_some-pod_some-ns_some-uid_0" , testContainerSandboxID , testContainerSandboxName },
203203 Namespace : k8sContainerdNamespace ,
204204 },
205205 map [string ]string {},
206206 },
207207 {
208208 mockcontainerdClient (testContainers , nil , nil , nil , nil ),
209- "/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9" ,
209+ testContainerSandboxName ,
210210 & mockedMachineInfo {},
211211 nil ,
212212 & containerlibcontainer.CgroupSubsystems {},
@@ -216,16 +216,16 @@ func TestHandler(t *testing.T) {
216216 false ,
217217 "" ,
218218 & info.ContainerReference {
219- Id : "40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9" ,
220- Name : "/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9" ,
221- Aliases : []string {"k8s_POD_some-pod_some-ns_some-uid_0" , "40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9" , "/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9" },
219+ Id : testContainerSandboxID ,
220+ Name : testContainerSandboxName ,
221+ Aliases : []string {"k8s_POD_some-pod_some-ns_some-uid_0" , testContainerSandboxID , testContainerSandboxName },
222222 Namespace : k8sContainerdNamespace ,
223223 },
224224 map [string ]string {"TEST_REGION" : "FRA" , "TEST_ZONE" : "A" },
225225 },
226226 {
227227 mockcontainerdClient (testContainers , testStatus , nil , nil , nil ),
228- "/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/c6a1aa99f14d3e57417e145b897e34961145f6b6f14216a176a34bfabbf79086" ,
228+ testContainerName ,
229229 & mockedMachineInfo {},
230230 nil ,
231231 & containerlibcontainer.CgroupSubsystems {},
@@ -235,9 +235,9 @@ func TestHandler(t *testing.T) {
235235 false ,
236236 "" ,
237237 & info.ContainerReference {
238- Id : "c6a1aa99f14d3e57417e145b897e34961145f6b6f14216a176a34bfabbf79086" ,
239- Name : "/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/c6a1aa99f14d3e57417e145b897e34961145f6b6f14216a176a34bfabbf79086" ,
240- Aliases : []string {"k8s_some-container_some-pod_some-ns_some-uid_2" , "c6a1aa99f14d3e57417e145b897e34961145f6b6f14216a176a34bfabbf79086" , "/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/c6a1aa99f14d3e57417e145b897e34961145f6b6f14216a176a34bfabbf79086" },
238+ Id : testContainerID ,
239+ Name : testContainerName ,
240+ Aliases : []string {"k8s_some-container_some-pod_some-ns_some-uid_2" , testContainerID , testContainerName },
241241 Namespace : k8sContainerdNamespace ,
242242 },
243243 map [string ]string {},
@@ -298,7 +298,7 @@ func TestHandlerDiskUssage(t *testing.T) {
298298 {
299299 Device : "/dev/sda" ,
300300 Capacity : 100 ,
301- Inodes : 10 ,
301+ Inodes : testInodesTotal ,
302302 Type : "fake type" ,
303303 },
304304 },
@@ -333,6 +333,7 @@ func TestHandlerDiskUssage(t *testing.T) {
333333 nil ,
334334 metricSet ,
335335 )
336+ // Regardless whether disk usage has error, the handler must be successfully created without error
336337 as .Nil (err )
337338 h := handler .(* containerdContainerHandler )
338339
@@ -366,7 +367,7 @@ func TestUsageProvider(t *testing.T) {
366367 } {
367368 up := fsUsageProvider {
368369 ctx : context .Background (),
369- containerID : testContainerId ,
370+ containerID : testContainerID ,
370371 client : ts .client ,
371372 fsInfo : ts .fsInfo ,
372373 logPath : testLogPath ,
0 commit comments