tests: no stdin for adapter

Signed-off-by: Lars Wirzenius <liw@liw.fi>
This commit is contained in:
Lars Wirzenius
2024-01-10 17:38:05 +02:00
parent f660492c48
commit 6083f087d7
+25 -2
View File
@@ -172,6 +172,15 @@ class Suite:
error = resps[1]["result"]["error"]
assert commit in error
def test_no_message(self):
git = self._create_git_repo("no-message")
self._create_valid_native_yaml(git, "echo hello world")
ci = self._create_ci()
exit, resps, stderr = ci.run_without_request()
assert exit != 0
assert len(resps) == 0
def test_malformed_trigger(self):
git = self._create_git_repo("malformed-trigger")
self._create_valid_native_yaml(git, "echo hello world")
@@ -334,6 +343,20 @@ class NativeCI:
resps = [json.loads(line.strip()) for line in p.stdout.splitlines()]
return p.returncode, resps, p.stderr
def run_without_request(self):
p = run(
[
"cargo",
"run",
"-q",
],
stdin=subprocess.DEVNULL,
env=dict(self.env),
may_fail=True,
)
resps = [json.loads(line.strip()) for line in p.stdout.splitlines()]
return p.returncode, resps, p.stderr
def debug(msg):
logging.debug(msg)
@@ -348,14 +371,14 @@ def die(msg, exc_info=None):
sys.exit(1)
def run(argv, env=None, cwd=None, input=None, may_fail=False):
def run(argv, env=None, cwd=None, stdin=None, input=None, may_fail=False):
debug(f"run {argv} with env={env}, cwd={cwd} input={input!r}")
if env is not None:
for name, value in os.environ.items():
if name not in env:
env[name] = value
p = subprocess.run(
argv, capture_output=True, env=env, cwd=cwd, input=input, text=True
argv, capture_output=True, env=env, cwd=cwd, stdin=stdin, input=input, text=True
)
debug(f"stdout:\n{indent(p.stdout)}")