@@ -154,8 +154,10 @@ func TestPodInfo(t *testing.T) {
154154 mock .Anything ,
155155 mock .Anything ,
156156 ).Return (nil )
157- _ , _ , err := pi .LookupByContainerID ("container1" )
158- assert .ErrorIs (t , err , ErrNoPod , "unexpected error returned" )
157+ containerInfo , found , err := pi .LookupByContainerID ("container1" )
158+ assert .NoError (t , err )
159+ assert .False (t , found , "expected container not to be found" )
160+ assert .Nil (t , containerInfo , "expected nil container info" )
159161 })
160162 t .Run ("exactly one pod found" , func (t * testing.T ) {
161163 pi := NewInformer ()
@@ -179,12 +181,14 @@ func TestPodInfo(t *testing.T) {
179181 pods := args .Get (1 ).(* corev1.PodList )
180182 pods .Items = []corev1.Pod {pod1 }
181183 })
182- retPod , containerName , err := pi .LookupByContainerID ("container1" )
184+ containerInfo , found , err := pi .LookupByContainerID ("container1" )
183185 assert .NoError (t , err )
184- assert .Equal (t , string (pod1 .UID ), retPod .ID , "unexpected pod id" )
185- assert .Equal (t , pod1 .Name , retPod .Name , "unexpected pod name" )
186- assert .Equal (t , pod1 .Namespace , retPod .Namespace , "unexpected pod namespace" )
187- assert .Equal (t , "" , containerName , "expected empty container name" )
186+ assert .True (t , found , "expected container to be found" )
187+ assert .NotNil (t , containerInfo , "expected non-nil container info" )
188+ assert .Equal (t , string (pod1 .UID ), containerInfo .PodID , "unexpected pod id" )
189+ assert .Equal (t , pod1 .Name , containerInfo .PodName , "unexpected pod name" )
190+ assert .Equal (t , pod1 .Namespace , containerInfo .Namespace , "unexpected pod namespace" )
191+ assert .Equal (t , "" , containerInfo .ContainerName , "expected empty container name" )
188192 })
189193 t .Run ("more than one pod found" , func (t * testing.T ) {
190194 pi := NewInformer ()
@@ -208,7 +212,8 @@ func TestPodInfo(t *testing.T) {
208212 pods := args .Get (1 ).(* corev1.PodList )
209213 pods .Items = []corev1.Pod {pod1 , pod1 }
210214 })
211- _ , _ , err := pi .LookupByContainerID ("container1" )
215+ _ , found , err := pi .LookupByContainerID ("container1" )
216+ assert .False (t , found , "expected container not to be found due to multiple pods" )
212217 assert .ErrorContains (t , err , "multiple pods found for containerID" )
213218 })
214219 t .Run ("cache error" , func (t * testing.T ) {
@@ -223,7 +228,8 @@ func TestPodInfo(t *testing.T) {
223228 mock .Anything ,
224229 mock .Anything ,
225230 ).Return (fmt .Errorf ("!!you shall not pass!!" ))
226- _ , _ , err := pi .LookupByContainerID ("container1" )
231+ _ , found , err := pi .LookupByContainerID ("container1" )
232+ assert .False (t , found , "expected container not to be found due to cache error" )
227233 assert .ErrorContains (t , err , "error retrieving pod info from cache" )
228234 })
229235}
@@ -280,14 +286,14 @@ func TestPodInformer_RunIntegration(t *testing.T) {
280286
281287 time .Sleep (50 * time .Millisecond )
282288
283- podInfo , containerName , err := pi .LookupByContainerID ("abc123" )
289+ containerInfo , found , err := pi .LookupByContainerID ("abc123" )
284290 if err != nil {
285291 t .Logf ("LookupByContainerID lookup failed (expected in fake setup): %v" , err )
286- } else {
287- assert .Equal (t , "test-pod" , podInfo . Name )
288- assert .Equal (t , "default" , podInfo .Namespace )
289- assert .Equal (t , "test-uid-123" , podInfo . ID )
290- assert .Equal (t , "test-container" , containerName )
292+ } else if found {
293+ assert .Equal (t , "test-pod" , containerInfo . PodName )
294+ assert .Equal (t , "default" , containerInfo .Namespace )
295+ assert .Equal (t , "test-uid-123" , containerInfo . PodID )
296+ assert .Equal (t , "test-container" , containerInfo . ContainerName )
291297 }
292298
293299 cancel ()
0 commit comments