def test_pod_containers_pod_without_node(self) -> None:
        pod = client.V1Pod(
            status=client.V1PodStatus(container_statuses=None, ))

        container_info_api_list = pod_containers(pod)

        self.assertEqual(container_info_api_list, {})
 def test_parse_containers(self, core_client, dummy_host):
     mocked_pods = {
         "kind":
         "PodList",
         "apiVersion":
         "v1",
         "metadata": {
             "selfLink": "/api/v1/pods",
             "resourceVersion": "6605101"
         },
         "items": [{
             "status": {
                 "containerStatuses": [{
                     "name": "cadvisor",
                     "state": {
                         "running": {
                             "startedAt": "2021-10-08T07:39:10Z"
                         }
                     },
                     "lastState": {},
                     "ready": True,
                     "restartCount": 0,
                     "image": "some_image",
                     "imageID": "some_irrelevant_id",
                     "containerID": "some_container_id",
                     "started": True,
                 }],
             },
         }],
     }
     Entry.single_register(
         Entry.GET,
         f"{dummy_host}/api/v1/pods",
         body=json.dumps(mocked_pods),
         headers={"content-type": "application/json"},
     )
     with Mocketizer():
         pod = list(core_client.list_pod_for_all_namespaces().items)[0]
     containers = pod_containers(pod)
     assert len(containers) == 1
     assert "cadvisor" in containers
     assert containers["cadvisor"].ready is True
     assert containers["cadvisor"].state.type == "running"
     assert containers["cadvisor"].image == "some_image"
     assert isinstance(containers["cadvisor"].state,
                       api.ContainerRunningState)
     assert isinstance(containers["cadvisor"].state.start_time, int)
 def test_pod_containers_start_up(self) -> None:
     """
     In this specific instance all of the fields expect for the scheduled field are missing.
     """
     container_statuses = [
         client.V1ContainerStatus(
             name="unready_container",
             ready=False,
             restart_count=0,
             container_id=None,
             image="gcr.io/kuar-demo/kuard-amd64:blue",
             image_id="",
             state=client.V1ContainerState(
                 running=None,
                 terminated=None,
                 waiting=client.V1ContainerStateWaiting(
                     message=None, reason="ContainerCreating"),
             ),
         )
     ]
     self.assertEqual(
         pod_containers(container_statuses),
         {
             "unready_container":
             api.ContainerStatus(
                 id=None,
                 name="unready_container",
                 image="gcr.io/kuar-demo/kuard-amd64:blue",
                 image_id="",
                 ready=False,
                 state=api.ContainerWaitingState(type="waiting",
                                                 reason="ContainerCreating",
                                                 detail=None),
                 restart_count=0,
             )
         },
     )
 def test_pod_containers_pod_without_node(self) -> None:
     """both initContainerStatuses and containerStatuses will be None, if a pod could not be
     scheduled. In this case, the containers and init_containers of the api.Pod is empty"""
     self.assertEqual(pod_containers(None), {})