From 49ff832f940ede1e5a92c6d444a55802c6fdd698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Roth?= Date: Tue, 23 Jul 2024 11:58:27 +0200 Subject: [PATCH] reenable lost tests --- system/t01_version/__init__.py | 11 ----- system/t01_version/version.py | 14 ++++++ system/t02_config/__init__.py | 63 -------------------------- system/t02_config/config.py | 66 +++++++++++++++++++++++++++ system/t03_help/__init__.py | 62 -------------------------- system/t03_help/help.py | 65 +++++++++++++++++++++++++++ system/t07_serve/__init__.py | 78 -------------------------------- system/t07_serve/serve.py | 81 ++++++++++++++++++++++++++++++++++ system/t12_api/unix_socket.py | 4 +- 9 files changed, 228 insertions(+), 216 deletions(-) create mode 100644 system/t01_version/version.py create mode 100644 system/t02_config/config.py create mode 100644 system/t03_help/help.py create mode 100644 system/t07_serve/serve.py diff --git a/system/t01_version/__init__.py b/system/t01_version/__init__.py index 388e7df6..e0a28e39 100644 --- a/system/t01_version/__init__.py +++ b/system/t01_version/__init__.py @@ -1,14 +1,3 @@ """ Test aptly version """ - -from lib import BaseTest - - -class VersionTest(BaseTest): - """ - version should match - """ - gold_processor = BaseTest.expand_environ - - runCmd = "aptly version" diff --git a/system/t01_version/version.py b/system/t01_version/version.py new file mode 100644 index 00000000..388e7df6 --- /dev/null +++ b/system/t01_version/version.py @@ -0,0 +1,14 @@ +""" +Test aptly version +""" + +from lib import BaseTest + + +class VersionTest(BaseTest): + """ + version should match + """ + gold_processor = BaseTest.expand_environ + + runCmd = "aptly version" diff --git a/system/t02_config/__init__.py b/system/t02_config/__init__.py index 240e5944..a5b0d2f4 100644 --- a/system/t02_config/__init__.py +++ b/system/t02_config/__init__.py @@ -1,66 +1,3 @@ """ Test config file """ - -import os -import re -import inspect -from lib import BaseTest - - -class CreateConfigTest(BaseTest): - """ - new file is generated if missing - """ - runCmd = "aptly mirror list" - checkedFile = os.path.join(os.environ["HOME"], ".aptly.conf") - - check = BaseTest.check_file - gold_processor = BaseTest.expand_environ - prepare = BaseTest.prepare_remove_all - - -class BadConfigTest(BaseTest): - """ - broken config file - """ - runCmd = "aptly mirror list" - expectedCode = 1 - - gold_processor = BaseTest.expand_environ - - def prepare(self): - self.prepare_remove_all() - - f = open(os.path.join(os.environ["HOME"], ".aptly.conf"), "w") - f.write("{some crap") - f.close() - - -class ConfigInFileTest(BaseTest): - """ - config in other file test - """ - runCmd = ["aptly", "mirror", "list", - "-config=%s" % (os.path.join(os.path.dirname(inspect.getsourcefile(BadConfigTest)), "aptly.conf"), )] - prepare = BaseTest.prepare_remove_all - - def outputMatchPrepare(_, s): - return re.sub(r' -(cpuprofile|memprofile|memstats|meminterval)=.*\n', '', s, flags=re.MULTILINE) - - -class ConfigInMissingFileTest(BaseTest): - """ - config in other file test - """ - runCmd = ["aptly", "mirror", "list", "-config=nosuchfile.conf"] - expectedCode = 1 - prepare = BaseTest.prepare_remove_all - - -class ConfigShowTest(BaseTest): - """ - config showing - """ - runCmd = ["aptly", "config", "show"] - gold_processor = BaseTest.expand_environ diff --git a/system/t02_config/config.py b/system/t02_config/config.py new file mode 100644 index 00000000..240e5944 --- /dev/null +++ b/system/t02_config/config.py @@ -0,0 +1,66 @@ +""" +Test config file +""" + +import os +import re +import inspect +from lib import BaseTest + + +class CreateConfigTest(BaseTest): + """ + new file is generated if missing + """ + runCmd = "aptly mirror list" + checkedFile = os.path.join(os.environ["HOME"], ".aptly.conf") + + check = BaseTest.check_file + gold_processor = BaseTest.expand_environ + prepare = BaseTest.prepare_remove_all + + +class BadConfigTest(BaseTest): + """ + broken config file + """ + runCmd = "aptly mirror list" + expectedCode = 1 + + gold_processor = BaseTest.expand_environ + + def prepare(self): + self.prepare_remove_all() + + f = open(os.path.join(os.environ["HOME"], ".aptly.conf"), "w") + f.write("{some crap") + f.close() + + +class ConfigInFileTest(BaseTest): + """ + config in other file test + """ + runCmd = ["aptly", "mirror", "list", + "-config=%s" % (os.path.join(os.path.dirname(inspect.getsourcefile(BadConfigTest)), "aptly.conf"), )] + prepare = BaseTest.prepare_remove_all + + def outputMatchPrepare(_, s): + return re.sub(r' -(cpuprofile|memprofile|memstats|meminterval)=.*\n', '', s, flags=re.MULTILINE) + + +class ConfigInMissingFileTest(BaseTest): + """ + config in other file test + """ + runCmd = ["aptly", "mirror", "list", "-config=nosuchfile.conf"] + expectedCode = 1 + prepare = BaseTest.prepare_remove_all + + +class ConfigShowTest(BaseTest): + """ + config showing + """ + runCmd = ["aptly", "config", "show"] + gold_processor = BaseTest.expand_environ diff --git a/system/t03_help/__init__.py b/system/t03_help/__init__.py index 07f1f828..bfd292b1 100644 --- a/system/t03_help/__init__.py +++ b/system/t03_help/__init__.py @@ -1,65 +1,3 @@ """ Test help screens """ - -import re -from lib import BaseTest - - -class MainTest(BaseTest): - """ - main - """ - expectedCode = 2 - runCmd = "aptly" - - def outputMatchPrepare(_, s): - return re.sub(r' -(cpuprofile|memprofile|memstats|meminterval)=.*\n', '', s, flags=re.MULTILINE) - - -class MirrorTest(BaseTest): - """ - main - """ - expectedCode = 2 - runCmd = "aptly mirror" - - -class MirrorCreateTest(BaseTest): - """ - main - """ - expectedCode = 2 - runCmd = "aptly mirror create" - - -class MainHelpTest(BaseTest): - """ - main - """ - runCmd = "aptly help" - - def outputMatchPrepare(_, s): - return re.sub(r' -(cpuprofile|memprofile|memstats|meminterval)=.*\n', '', s, flags=re.MULTILINE) - - -class MirrorHelpTest(BaseTest): - """ - main - """ - runCmd = "aptly help mirror" - - -class MirrorCreateHelpTest(BaseTest): - """ - main - """ - runCmd = "aptly help mirror create" - - -class WrongFlagTest(BaseTest): - """ - main - """ - expectedCode = 2 - runCmd = "aptly mirror create -fxz=sss" diff --git a/system/t03_help/help.py b/system/t03_help/help.py new file mode 100644 index 00000000..07f1f828 --- /dev/null +++ b/system/t03_help/help.py @@ -0,0 +1,65 @@ +""" +Test help screens +""" + +import re +from lib import BaseTest + + +class MainTest(BaseTest): + """ + main + """ + expectedCode = 2 + runCmd = "aptly" + + def outputMatchPrepare(_, s): + return re.sub(r' -(cpuprofile|memprofile|memstats|meminterval)=.*\n', '', s, flags=re.MULTILINE) + + +class MirrorTest(BaseTest): + """ + main + """ + expectedCode = 2 + runCmd = "aptly mirror" + + +class MirrorCreateTest(BaseTest): + """ + main + """ + expectedCode = 2 + runCmd = "aptly mirror create" + + +class MainHelpTest(BaseTest): + """ + main + """ + runCmd = "aptly help" + + def outputMatchPrepare(_, s): + return re.sub(r' -(cpuprofile|memprofile|memstats|meminterval)=.*\n', '', s, flags=re.MULTILINE) + + +class MirrorHelpTest(BaseTest): + """ + main + """ + runCmd = "aptly help mirror" + + +class MirrorCreateHelpTest(BaseTest): + """ + main + """ + runCmd = "aptly help mirror create" + + +class WrongFlagTest(BaseTest): + """ + main + """ + expectedCode = 2 + runCmd = "aptly mirror create -fxz=sss" diff --git a/system/t07_serve/__init__.py b/system/t07_serve/__init__.py index 457b9f59..1d3d2f7c 100644 --- a/system/t07_serve/__init__.py +++ b/system/t07_serve/__init__.py @@ -1,81 +1,3 @@ """ Testing serving public repo """ - -import http.client -import os -import signal -import subprocess -import shlex -import time - -from lib import BaseTest - - -class RootDirInaccessible(BaseTest): - """ - serve command aborts if rootDir is inaccessible - """ - skipTest = 'User is root' if os.environ['USER'] == 'root' else False - fixtureDB = False - fixturePool = False - - configOverride = { - "rootDir": "/root" # any directory that exists but is not writable - } - - runCmd = "aptly serve -listen=127.0.0.1:8765" - expectedCode = 1 - - -class Serve1Test(BaseTest): - """ - serve public: two publishes, verify HTTP - """ - fixtureDB = True - fixturePool = True - fixtureCmds = [ - "aptly snapshot create snap1 from mirror gnuplot-maverick", - "aptly snapshot create snap2 from mirror gnuplot-maverick-src", - "aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec snap1", - "aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec snap2 debian", - "aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -component=main,contrib snap1 snap2 multi", - ] - runCmd = "aptly serve -listen=127.0.0.1:8765" - - def run(self): - try: - proc = subprocess.Popen(shlex.split(self.runCmd), stderr=subprocess.STDOUT, stdout=subprocess.PIPE, bufsize=0) - - try: - time.sleep(1) - - conn = http.client.HTTPConnection("127.0.0.1", 8765) - conn.request("GET", "/") - r = conn.getresponse() - if r.status != 200: - raise Exception("Expected status 200 != %d" % r.status) - self.http_response = r.read() - - output = os.read(proc.stdout.fileno(), 8192) - - finally: - proc.send_signal(signal.SIGINT) - proc.wait() - - if proc.returncode != -2 and proc.returncode != 2: - raise Exception("exit code %d != %d (output: %s)" % (proc.returncode, -2, output)) - self.output = output - except Exception as e: - raise Exception("Running command %s failed: %s" % (self.runCmd, str(e))) - - def check(self): - self.check_output() - self.verify_match(self.get_gold('http'), self.http_response, match_prepare=lambda s: "\n".join(sorted(s.split("\n")))) - - -class Serve2Test(BaseTest): - """ - serve public: no publishes - """ - runCmd = "aptly serve -listen=127.0.0.1:8765" diff --git a/system/t07_serve/serve.py b/system/t07_serve/serve.py new file mode 100644 index 00000000..457b9f59 --- /dev/null +++ b/system/t07_serve/serve.py @@ -0,0 +1,81 @@ +""" +Testing serving public repo +""" + +import http.client +import os +import signal +import subprocess +import shlex +import time + +from lib import BaseTest + + +class RootDirInaccessible(BaseTest): + """ + serve command aborts if rootDir is inaccessible + """ + skipTest = 'User is root' if os.environ['USER'] == 'root' else False + fixtureDB = False + fixturePool = False + + configOverride = { + "rootDir": "/root" # any directory that exists but is not writable + } + + runCmd = "aptly serve -listen=127.0.0.1:8765" + expectedCode = 1 + + +class Serve1Test(BaseTest): + """ + serve public: two publishes, verify HTTP + """ + fixtureDB = True + fixturePool = True + fixtureCmds = [ + "aptly snapshot create snap1 from mirror gnuplot-maverick", + "aptly snapshot create snap2 from mirror gnuplot-maverick-src", + "aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec snap1", + "aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec snap2 debian", + "aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -component=main,contrib snap1 snap2 multi", + ] + runCmd = "aptly serve -listen=127.0.0.1:8765" + + def run(self): + try: + proc = subprocess.Popen(shlex.split(self.runCmd), stderr=subprocess.STDOUT, stdout=subprocess.PIPE, bufsize=0) + + try: + time.sleep(1) + + conn = http.client.HTTPConnection("127.0.0.1", 8765) + conn.request("GET", "/") + r = conn.getresponse() + if r.status != 200: + raise Exception("Expected status 200 != %d" % r.status) + self.http_response = r.read() + + output = os.read(proc.stdout.fileno(), 8192) + + finally: + proc.send_signal(signal.SIGINT) + proc.wait() + + if proc.returncode != -2 and proc.returncode != 2: + raise Exception("exit code %d != %d (output: %s)" % (proc.returncode, -2, output)) + self.output = output + except Exception as e: + raise Exception("Running command %s failed: %s" % (self.runCmd, str(e))) + + def check(self): + self.check_output() + self.verify_match(self.get_gold('http'), self.http_response, match_prepare=lambda s: "\n".join(sorted(s.split("\n")))) + + +class Serve2Test(BaseTest): + """ + serve public: no publishes + """ + runCmd = "aptly serve -listen=127.0.0.1:8765" diff --git a/system/t12_api/unix_socket.py b/system/t12_api/unix_socket.py index aa5ac2db..075ff688 100644 --- a/system/t12_api/unix_socket.py +++ b/system/t12_api/unix_socket.py @@ -6,7 +6,7 @@ import urllib.parse import urllib.request from lib import BaseTest -from api_lib import AptlyStream +from testout import TestOut class UnixSocketAPITest(BaseTest): @@ -18,7 +18,7 @@ class UnixSocketAPITest(BaseTest): def prepare(self): if self.aptly_server is None: - UnixSocketAPITest.aptly_out = AptlyStream() + UnixSocketAPITest.aptly_out = TestOut() self.aptly_server = self._start_process("aptly api serve -no-lock -listen=%s" % (self.base_url), stdout=UnixSocketAPITest.aptly_out, stderr=UnixSocketAPITest.aptly_out) time.sleep(1) else: