mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-01-11 03:11:50 +00:00
System test, first sketch.
This commit is contained in:
1
system/README.rst
Normal file
1
system/README.rst
Normal file
@@ -0,0 +1 @@
|
|||||||
|
System test for aptly
|
||||||
81
system/lib.py
Normal file
81
system/lib.py
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
"""
|
||||||
|
Test library.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import difflib
|
||||||
|
import inspect
|
||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import string
|
||||||
|
|
||||||
|
class BaseTest(object):
|
||||||
|
"""
|
||||||
|
Base class for all tests.
|
||||||
|
"""
|
||||||
|
|
||||||
|
expectedCode = 0
|
||||||
|
|
||||||
|
def test(self):
|
||||||
|
self.prepare()
|
||||||
|
self.run()
|
||||||
|
self.check()
|
||||||
|
|
||||||
|
def prepare_remove_all(self):
|
||||||
|
if os.path.exists(os.path.join(os.environ["HOME"], ".aptly")):
|
||||||
|
shutil.rmtree(os.path.join(os.environ["HOME"], ".aptly"))
|
||||||
|
if os.path.exists(os.path.join(os.environ["HOME"], ".aptly.conf")):
|
||||||
|
os.remove(os.path.join(os.environ["HOME"], ".aptly.conf"))
|
||||||
|
|
||||||
|
def prepare_default_config(self):
|
||||||
|
f = open(os.path.join(os.environ["HOME"], ".aptly.conf"), "w")
|
||||||
|
f.write(config_file)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
try:
|
||||||
|
proc = subprocess.Popen(self.runCmd.split(" "), stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
|
||||||
|
self.output, _ = proc.communicate()
|
||||||
|
if proc.returncode != self.expectedCode:
|
||||||
|
raise Exception("exit code %d != %d" % (proc.returncode, self.expectedCode))
|
||||||
|
except Exception, e:
|
||||||
|
raise Exception("Running command %s failed: %s" % (self.runCmd, str(e)))
|
||||||
|
|
||||||
|
def gold_processor(self, gold):
|
||||||
|
return gold
|
||||||
|
|
||||||
|
def expand_environ(self, gold):
|
||||||
|
return string.Template(gold).substitute(os.environ)
|
||||||
|
|
||||||
|
def get_gold(self):
|
||||||
|
gold = os.path.join(os.path.dirname(inspect.getsourcefile(self.__class__)), "gold")
|
||||||
|
return self.gold_processor(open(gold, "r").read())
|
||||||
|
|
||||||
|
def check_output(self):
|
||||||
|
self.verify_match(self.get_gold(), self.output)
|
||||||
|
|
||||||
|
def verify_match(self, a, b):
|
||||||
|
if a != b:
|
||||||
|
diff = "".join(difflib.unified_diff([l + "\n" for l in a.split("\n")], [l + "\n" for l in b.split("\n")]))
|
||||||
|
|
||||||
|
raise Exception("content doesn't match:\n" + diff + "\n")
|
||||||
|
|
||||||
|
def check_file(self):
|
||||||
|
self.verify_match(self.get_gold(), open(self.checkedFile, "r").read())
|
||||||
|
|
||||||
|
check = check_output
|
||||||
|
|
||||||
|
def prepare(self):
|
||||||
|
self.prepare_remove_all()
|
||||||
|
self.prepare_default_config()
|
||||||
|
|
||||||
|
config_file = """
|
||||||
|
{
|
||||||
|
"rootDir": "%s/.aptly",
|
||||||
|
"downloadConcurrency": 4,
|
||||||
|
"architectures": [],
|
||||||
|
"dependencyFollowSuggests": false,
|
||||||
|
"dependencyFollowRecommends": false,
|
||||||
|
"dependencyFollowAllVariants": false
|
||||||
|
}
|
||||||
|
""" % (os.environ["HOME"])
|
||||||
39
system/run.py
Executable file
39
system/run.py
Executable file
@@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import glob
|
||||||
|
import importlib
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def run():
|
||||||
|
"""
|
||||||
|
Run system test.
|
||||||
|
"""
|
||||||
|
tests = glob.glob("t*_*")
|
||||||
|
fails = []
|
||||||
|
|
||||||
|
for test in tests:
|
||||||
|
sys.stdout.write("%s..." % (test, ))
|
||||||
|
|
||||||
|
testModule = importlib.import_module(test)
|
||||||
|
t = testModule.Test()
|
||||||
|
|
||||||
|
try:
|
||||||
|
t.test()
|
||||||
|
except BaseException, e:
|
||||||
|
fails.append((test, t, e, testModule))
|
||||||
|
sys.stdout.write("FAIL\n")
|
||||||
|
else:
|
||||||
|
sys.stdout.write("OK\n")
|
||||||
|
|
||||||
|
if len(fails) > 0:
|
||||||
|
print "\nFAILURES (%d):" % (len(fails), )
|
||||||
|
|
||||||
|
for (test, t, e, testModule) in fails:
|
||||||
|
print "%s: %s" % (test, testModule.__doc__.strip())
|
||||||
|
print "ERROR: %s" % (e, )
|
||||||
|
print "=" * 60
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run()
|
||||||
9
system/t01_version/__init__.py
Normal file
9
system/t01_version/__init__.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
"""
|
||||||
|
Test aptly version.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from lib import BaseTest
|
||||||
|
|
||||||
|
|
||||||
|
class Test(BaseTest):
|
||||||
|
runCmd = "aptly version"
|
||||||
1
system/t01_version/gold
Normal file
1
system/t01_version/gold
Normal file
@@ -0,0 +1 @@
|
|||||||
|
aptly version: 0.2
|
||||||
15
system/t02_config/__init__.py
Normal file
15
system/t02_config/__init__.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
"""
|
||||||
|
Test config file generation.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
from lib import BaseTest
|
||||||
|
|
||||||
|
|
||||||
|
class Test(BaseTest):
|
||||||
|
runCmd = "aptly"
|
||||||
|
checkedFile = os.path.join(os.environ["HOME"], ".aptly.conf")
|
||||||
|
|
||||||
|
check = BaseTest.check_file
|
||||||
|
gold_processor = BaseTest.expand_environ
|
||||||
|
prepare = BaseTest.prepare_remove_all
|
||||||
8
system/t02_config/gold
Normal file
8
system/t02_config/gold
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"rootDir": "${HOME}/.aptly",
|
||||||
|
"downloadConcurrency": 4,
|
||||||
|
"architectures": [],
|
||||||
|
"dependencyFollowSuggests": false,
|
||||||
|
"dependencyFollowRecommends": false,
|
||||||
|
"dependencyFollowAllVariants": false
|
||||||
|
}
|
||||||
18
system/t03_bad_config/__init__.py
Normal file
18
system/t03_bad_config/__init__.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
"""
|
||||||
|
Start with bad config.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
from lib import BaseTest
|
||||||
|
|
||||||
|
|
||||||
|
class Test(BaseTest):
|
||||||
|
runCmd = "aptly"
|
||||||
|
expectedCode = 1
|
||||||
|
|
||||||
|
def prepare(self):
|
||||||
|
self.prepare_remove_all()
|
||||||
|
|
||||||
|
f = open(os.path.join(os.environ["HOME"], ".aptly.conf"), "w")
|
||||||
|
f.write("{some crap")
|
||||||
|
f.close()
|
||||||
1
system/t03_bad_config/gold
Normal file
1
system/t03_bad_config/gold
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ERROR: error loading config file /Users/smira/.aptly.conf: invalid character 's' looking for beginning of object key string
|
||||||
Reference in New Issue
Block a user