Skip to content

Commit

Permalink
New test for default licenses
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Nov 3, 2023
1 parent fcb8f38 commit 9b163f5
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
5 changes: 4 additions & 1 deletion testsuite/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ RUN apt-get update && apt-get install -y \
sudo \
util-linux # for `unshare`

RUN pip3 install e3-testsuite
# Use parent testsuite python packages here too, as they are potential imports
# of the drivers and helpers that may be needed in the wrapped test.
COPY ./testsuite/requirements.txt /testsuite/requirements.txt
RUN pip3 install -r /testsuite/requirements.txt

WORKDIR /testsuite
USER user
29 changes: 29 additions & 0 deletions testsuite/drivers/alr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import os
import os.path
import pexpect
import re
from shutil import copytree

Expand Down Expand Up @@ -127,6 +128,34 @@ def run_alr(*args, **kwargs):
return ProcessResult(p.status, p.out.replace('\r\n', '\n'))


def run_alr_interactive(args: [str], input: [str], timeout=5) -> str:
"""
Run "alr" with the given arguments, feeding it the given input. No other
arguments like -q or -d are added.
:param args: List of arguments to pass to "alr".
:param input: String to feed to the subprocess's standard input.
:param timeout: Timeout in seconds for the subprocess to complete.
"""
# Run interactively using pexpect (run with input fails as it is not
# detected as tty and input is closed prematurely)
child = pexpect.spawn('alr', args=args, timeout=timeout)
for line in input:
child.sendline(line)

# Wait for the process to finish
child.expect(pexpect.EOF)
child.close()

# Assert proper output code
assert child.exitstatus == 0, \
f"Unexpected exit status: {child.exitstatus}\n" + \
f"Output: {child.before.decode('utf-8')}"

# Return command output
return child.before.decode('utf-8')


def fixtures_path(*args):
"""
Return a path under the testsuite `fixtures` directory.
Expand Down
1 change: 1 addition & 0 deletions testsuite/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
docker
e3-testsuite
pexpect
32 changes: 32 additions & 0 deletions testsuite/tests/init/default-licenses/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
Check that offered default licenses are all valid
"""

import os
import shutil

from drivers.alr import run_alr, run_alr_interactive

# iterate over values 1..8
for i in range(1, 9):

# Run interactively
run_alr_interactive(['init', '--bin', 'xxx'],
input=['', # Description
'', # Full user name
'', # Github login
'', # Email
f'{i}', # License
'', # Tags
''], # Website
timeout=3)

# Check that it can be shown, which will load the manifest
os.chdir("xxx")
p = run_alr("show")

# Prepare for next iteration
os.chdir("..")
shutil.rmtree("xxx")

print('SUCCESS')
2 changes: 2 additions & 0 deletions testsuite/tests/init/default-licenses/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
driver: python-script
indexes: {}

0 comments on commit 9b163f5

Please sign in to comment.