def test_get_output(): count = 11**5 cmd = ["python3", "-c", "for idx in range({}): print(idx)".format(count)] # Test verbose == False runner = Runner("/dev/null", False) data = runner.get_output(cmd) lines = data.splitlines() assert len(lines) == count # Test verbose == True runner = Runner("/dev/null", True) data = runner.get_output(cmd) lines = data.splitlines() assert len(lines) == count
def test_check_call_timeout(): code = "import time\nfor n in range(100):\n print(n)\n time.sleep(0.05)" cmd = ["python3", "-c", code] # Test verbose == False runner = Runner("-", False) with pytest.raises(subprocess.TimeoutExpired): # as exc_info runner.check_call(cmd, timeout=0.5) # FIXME output capture is broken. Everything appears at the end, which # means in the timeout case, no output is ever captured. ''' output = exc_info.value.output assert "0" in output # FIXME assert "1" in output ''' # Test verbose == True runner = Runner("-", True) with pytest.raises(subprocess.TimeoutExpired): # as exc_info runner.check_call(cmd, timeout=0.5) # FIXME output capture is broken. Everything appears at the end, which # means in the timeout case, no output is ever captured. '''
def test_swap_deployment_changes(): """ The modified Deployment used to swap out an existing Deployment replaces all values that might break our own image. """ runner = Runner("-", False) runner.kubectl = KubeInfo( "cluster", "cluster_version", False, # cluster_is_openshift "kubectl", "command_version", "server", "context", "namespace", False, # in_local_vm False, # verbose ) # Original has a privileged port original = yaml.safe_load(COMPLEX_DEPLOYMENT) expected = yaml.safe_load(SWAPPED_DEPLOYMENT) ports = telepresence.cli.PortMapping.parse(["9999"]) actual = telepresence.proxy.deployment.new_swapped_deployment( runner, original, "nginxhttps", "random_id_123", ports, "", False) image = actual["spec"]["template"]["spec"]["containers"][1]["image"] assert "/telepresence-k8s-priv:" in image expected["spec"]["template"]["spec"]["containers"][1]["image"] = image assert actual == expected assert (9999, 9999) in ports.local_to_remote() assert (80, 80) in ports.local_to_remote() # Test w/o privileged port. original = yaml.safe_load(COMPLEX_DEPLOYMENT) original["spec"]["template"]["spec"]["containers"][1]["ports"][0][ "containerPort"] = 8080 expected = yaml.safe_load(SWAPPED_DEPLOYMENT) expected["spec"]["template"]["spec"]["containers"][1]["ports"][0][ "containerPort"] = 8080 ports = telepresence.cli.PortMapping.parse(["9999"]) actual = telepresence.proxy.deployment.new_swapped_deployment( runner, original, "nginxhttps", "random_id_123", ports, "", False) image = actual["spec"]["template"]["spec"]["containers"][1]["image"] assert "/telepresence-k8s:" in image expected["spec"]["template"]["spec"]["containers"][1]["image"] = image assert actual == expected assert (9999, 9999) in ports.local_to_remote() assert (8080, 8080) in ports.local_to_remote() # Test with OpenShift. runner.kubectl = runner.kubectl._replace( command="oc", cluster_is_openshift=True, ) original = yaml.safe_load(COMPLEX_DEPLOYMENT) original["spec"]["template"]["spec"]["containers"][1]["ports"][0][ "containerPort"] = 8080 expected = yaml.safe_load(SWAPPED_DEPLOYMENT) expected["spec"]["template"]["spec"]["containers"][1]["ports"][0][ "containerPort"] = 8080 ports = telepresence.cli.PortMapping.parse(["9999"]) actual = telepresence.proxy.deployment.new_swapped_deployment( runner, original, "nginxhttps", "random_id_123", ports, "", False) image = actual["spec"]["template"]["spec"]["containers"][1]["image"] assert "/telepresence-ocp:" in image expected["spec"]["template"]["spec"]["containers"][1]["image"] = image assert actual == expected assert (9999, 9999) in ports.local_to_remote() assert (8080, 8080) in ports.local_to_remote()