reenable lost tests

This commit is contained in:
André Roth
2024-07-23 11:58:27 +02:00
parent 09a44ba409
commit 49ff832f94
9 changed files with 228 additions and 216 deletions

View File

@@ -1,14 +1,3 @@
""" """
Test aptly version Test aptly version
""" """
from lib import BaseTest
class VersionTest(BaseTest):
"""
version should match
"""
gold_processor = BaseTest.expand_environ
runCmd = "aptly version"

View File

@@ -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"

View File

@@ -1,66 +1,3 @@
""" """
Test config file 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

View File

@@ -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

View File

@@ -1,65 +1,3 @@
""" """
Test help screens 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"

65
system/t03_help/help.py Normal file
View File

@@ -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"

View File

@@ -1,81 +1,3 @@
""" """
Testing serving public repo 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"

81
system/t07_serve/serve.py Normal file
View File

@@ -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"

View File

@@ -6,7 +6,7 @@ import urllib.parse
import urllib.request import urllib.request
from lib import BaseTest from lib import BaseTest
from api_lib import AptlyStream from testout import TestOut
class UnixSocketAPITest(BaseTest): class UnixSocketAPITest(BaseTest):
@@ -18,7 +18,7 @@ class UnixSocketAPITest(BaseTest):
def prepare(self): def prepare(self):
if self.aptly_server is None: 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) 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) time.sleep(1)
else: else: