From 84b4f913cfeadd6ddce19d0d4ad14e1d380a2b97 Mon Sep 17 00:00:00 2001 From: AbcSxyZ Date: Sat, 18 Dec 2021 20:23:17 +0100 Subject: [PATCH] Restore run commands to DockerRunner --- tests/integration/framework/docker_runner.py | 14 +++++++++----- tests/integration/framework/test_runner.py | 14 ++++++++++++-- tests/integration/version.py | 6 +++--- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/tests/integration/framework/docker_runner.py b/tests/integration/framework/docker_runner.py index 1b6fee9..a4e36fe 100644 --- a/tests/integration/framework/docker_runner.py +++ b/tests/integration/framework/docker_runner.py @@ -21,11 +21,15 @@ def __init__(self, platform, image, verbose): self._start() def execute(self, envs, args): + """Launch `docker exec` commands inside the background container""" + command = self._construct_command("exec", envs, args) + return self._shell(command) + + def run(self, envs, args): """ - Run our target docker image with a list of - environment variables and a list of arguments + Launch `docker run` commands to create a new container for each command """ - command = self._construct_command(envs, args) + command = self._construct_command("run", envs, args) return self._shell(command) def __del__(self): @@ -68,9 +72,9 @@ def _shell(self, command, silent=False): return result.stdout.decode("utf-8").strip() - def _construct_command(self, envs, args): + def _construct_command(self, docker_cmd, envs, args): """Construct a docker command with env and args""" - command = ["docker", "exec"] + command = ["docker", docker_cmd] for env in envs: command.append("-e") diff --git a/tests/integration/framework/test_runner.py b/tests/integration/framework/test_runner.py index d45f072..3bd3206 100644 --- a/tests/integration/framework/test_runner.py +++ b/tests/integration/framework/test_runner.py @@ -25,13 +25,23 @@ def run_test(self): """Actual test, must be implemented by the final class""" raise NotImplementedError - def run_command(self, envs, args): - """Run a docker command with env and args""" + def docker_exec(self, envs, args): + """ + Launch `docker exec` command, run command inside a background container. + Let execute mutliple instructions in the same container. + """ assert self.options.platform is not None assert self.options.image is not None return self.container.execute(envs, args) + def docker_run(self, envs, args): + """Launch `docker run` command, create a new container for each run""" + assert self.options.platform is not None + assert self.options.image is not None + + return self.container.run(envs, args) + def main(self): """main loop""" parser = argparse.ArgumentParser() diff --git a/tests/integration/version.py b/tests/integration/version.py index 59b24a5..68e86c6 100644 --- a/tests/integration/version.py +++ b/tests/integration/version.py @@ -27,15 +27,15 @@ def run_test(self): self.version_expr = re.compile(f".*{ self.options.version }.*") # check dogecoind with only env - dogecoind = self.run_command(["VERSION=1"], []) + dogecoind = self.docker_exec(["VERSION=1"], []) self.ensure_version_on_first_line(dogecoind) # check dogecoin-cli - dogecoincli = self.run_command([], ["dogecoin-cli", "-?"]) + dogecoincli = self.docker_exec([], ["dogecoin-cli", "-?"]) self.ensure_version_on_first_line(dogecoincli) # check dogecoin-tx - dogecointx = self.run_command([], ["dogecoin-tx", "-?"]) + dogecointx = self.docker_exec([], ["dogecoin-tx", "-?"]) self.ensure_version_on_first_line(dogecointx) # make sure that we find version errors