def test_get_pod_manifest_tolerates_mixed_input(): """ Test that the get_pod_manifest function can handle a either a dictionary or an object both representing V1Container objects and that the function returns a V1Pod object containing V1Container objects. """ c = Config() dict_model = { 'name': 'mock_name_1', 'image': 'mock_image_1', 'command': ['mock_command_1'] } object_model = V1Container( name="mock_name_2", image="mock_image_2", command=['mock_command_2'], security_context=V1SecurityContext( privileged=True, run_as_user=0, capabilities=V1Capabilities(add=['NET_ADMIN']) ) ) c.KubeSpawner.init_containers = [dict_model, object_model] spawner = KubeSpawner(config=c, _mock=True) # this test ensures the following line doesn't raise an error manifest = sync_wait(spawner.get_pod_manifest()) # and tests the return value's types assert isinstance(manifest, V1Pod) assert isinstance(manifest.spec.init_containers[0], V1Container) assert isinstance(manifest.spec.init_containers[1], V1Container)
def test_update_k8s_model(): """Ensure update_k8s_model does what it should. The test is first updating attributes using the function and then and manually verifies that the correct changes have been made.""" manually_updated_target = V1Container( name="mock_name", image="mock_image", command=['iptables'], security_context=V1SecurityContext( privileged=True, run_as_user=0, capabilities=V1Capabilities(add=['NET_ADMIN']))) target = copy.deepcopy(manually_updated_target) source = {"name": "new_mock_name"} update_k8s_model(target, source) manually_updated_target.name = "new_mock_name" assert target == manually_updated_target