Skip to content

Commit

Permalink
Restore run commands to DockerRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
AbcSxyZ committed Dec 18, 2021
1 parent 02a9074 commit 84b4f91
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
14 changes: 9 additions & 5 deletions tests/integration/framework/docker_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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")
Expand Down
14 changes: 12 additions & 2 deletions tests/integration/framework/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 84b4f91

Please sign in to comment.