-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DockerRunner: Enable background container to run commands against #51
base: main
Are you sure you want to change the base?
Changes from all commits
02a9074
84b4f91
eba0eb9
b8d2171
9b3ac80
eb89b6c
62a40d5
775eec6
407dbac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,8 @@ class TestConfigurationError(Exception): | |
class TestRunner: | ||
"""Base class to define and run Dogecoin Core Docker tests with""" | ||
def __init__(self): | ||
"""Make sure there is an options object""" | ||
self.options = {} | ||
self.docker_cli = None | ||
|
||
def add_options(self, parser): | ||
"""Allow adding options in tests""" | ||
|
@@ -25,15 +25,22 @@ def run_test(self): | |
"""Actual test, must be implemented by the final class""" | ||
raise NotImplementedError | ||
|
||
def run_command(self, envs, args): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please restore this so that version test doesn't have to change |
||
"""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 | ||
|
||
runner = DockerRunner(self.options.platform, | ||
self.options.image, self.options.verbose) | ||
return self.docker_cli.execute(envs, args) | ||
|
||
return runner.run_interactive_command(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.docker_cli.run(envs, args) | ||
|
||
def main(self): | ||
"""main loop""" | ||
|
@@ -48,6 +55,9 @@ def main(self): | |
self.add_options(parser) | ||
self.options = parser.parse_args() | ||
|
||
self.docker_cli = DockerRunner(self.options.platform, | ||
self.options.image, self.options.verbose) | ||
|
||
self.run_test() | ||
print("Tests successful") | ||
sys.exit(0) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,21 +27,21 @@ def run_test(self): | |
self.version_expr = re.compile(f".*{ self.options.version }.*") | ||
|
||
# check dogecoind with only env | ||
dogecoind = self.run_command(["VERSION=1"], []) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert all changes to this file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
self.ensure_version_on_first_line(dogecoind.stdout) | ||
dogecoind = self.docker_run(["VERSION=1"], []) | ||
self.ensure_version_on_first_line(dogecoind) | ||
|
||
# check dogecoin-cli | ||
dogecoincli = self.run_command([], ["dogecoin-cli", "-?"]) | ||
self.ensure_version_on_first_line(dogecoincli.stdout) | ||
dogecoincli = self.docker_run([], ["dogecoin-cli", "-?"]) | ||
self.ensure_version_on_first_line(dogecoincli) | ||
|
||
# check dogecoin-tx | ||
dogecointx = self.run_command([], ["dogecoin-tx", "-?"]) | ||
self.ensure_version_on_first_line(dogecointx.stdout) | ||
dogecointx = self.docker_run([], ["dogecoin-tx", "-?"]) | ||
self.ensure_version_on_first_line(dogecointx) | ||
|
||
# make sure that we find version errors | ||
caught_error = False | ||
try: | ||
self.ensure_version_on_first_line("no version here".encode('utf-8')) | ||
self.ensure_version_on_first_line("no version here") | ||
except AssertionError: | ||
caught_error = True | ||
|
||
|
@@ -50,7 +50,7 @@ def run_test(self): | |
|
||
def ensure_version_on_first_line(self, cmd_output): | ||
"""Assert that the version is contained in the first line of output string""" | ||
first_line = cmd_output.decode("utf-8").split("\n")[0] | ||
first_line = cmd_output.split("\n")[0] | ||
|
||
if re.match(self.version_expr, first_line) is None: | ||
text = f"Could not find version { self.options.version } in { first_line }" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please bring this method back so that the tests don't have to change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related to #51 (comment)