Skip to content

Commit

Permalink
add first test of addon files
Browse files Browse the repository at this point in the history
  • Loading branch information
reglim committed May 31, 2023
1 parent 971d7d8 commit 3fc792b
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
9 changes: 9 additions & 0 deletions system/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,15 @@ def check_cmd_output(self, command, gold_name, match_prepare=None, expected_code
else:
raise

def write_file(self, path, content):
full_path = os.path.join(os.environ["HOME"], ".aptly", path)

if not os.path.exists(os.path.dirname(full_path)):
os.makedirs(os.path.dirname(full_path), 0o755)

with open(full_path, "w") as f:
f.write(content)

def read_file(self, path, mode=''):
with open(os.path.join(os.environ["HOME"], self.aptlyDir, path), "r" + mode) as f:
return f.read()
Expand Down
14 changes: 14 additions & 0 deletions system/t06_publish/PublishRepo34Test_gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Loading packages...
Generating metadata files and linking package files...
Finalizing metadata files...
Signing file 'Release' with gpg, please enter your passphrase when prompted:
Clearsigning file 'Release' with gpg, please enter your passphrase when prompted:

Local repo local-repo has been successfully published.
Please setup your webserver to serve directory '${HOME}/.aptly/public' with autoindexing.
Now you can add following line to apt sources:
deb http://your-server/ maverick main
deb-src http://your-server/ maverick main
Don't forget to add your GPG key to apt with apt-key.

You can also use `aptly serve` to publish your repositories over HTTP quickly.
58 changes: 58 additions & 0 deletions system/t06_publish/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,3 +888,61 @@ def check(self):
self.check_exists('public/dists/maverick/main/binary-amd64/Packages')
self.check_exists('public/dists/maverick/main/binary-amd64/Packages.gz')
self.check_not_exists('public/dists/maverick/main/binary-amd64/Packages.bz2')


class PublishRepo34Test(BaseTest):
"""
publish repo: addon files
"""
fixtureCmds = [
"aptly repo create local-repo",
"aptly repo add local-repo ${files}"
]
runCmd = "aptly publish repo -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -distribution=maverick -skip-contents local-repo"
gold_processor = BaseTest.expand_environ

def prepare_fixture(self):
super(PublishRepo34Test, self).prepare_fixture()

self.write_file(os.path.join('addon', 'dists', 'maverick', 'main', 'dep11', 'README'), 'README test file')

def check(self):
super(PublishRepo34Test, self).check()

self.check_exists('public/dists/maverick/main/dep11/README')

self.check_exists('public/dists/maverick/Release')

readme = self.read_file('public/dists/maverick/main/dep11/README')
if readme != 'README test file':
raise Exception("README file not copied on publish")

release = self.read_file('public/dists/maverick/Release').split("\n")
release = [l for l in release if l.startswith(" ")]
pathsSeen = set()
for l in release:
fileHash, fileSize, path = l.split()
pathsSeen.add(path)

fileSize = int(fileSize)

st = os.stat(os.path.join(os.environ["HOME"], ".aptly", 'public/dists/maverick/', path))
if fileSize != st.st_size:
raise Exception("file size doesn't match for %s: %d != %d" % (path, fileSize, st.st_size))

if len(fileHash) == 32:
h = hashlib.md5()
elif len(fileHash) == 40:
h = hashlib.sha1()
elif len(fileHash) == 64:
h = hashlib.sha256()
else:
h = hashlib.sha512()

h.update(self.read_file(os.path.join('public/dists/maverick', path), mode='b'))

if h.hexdigest() != fileHash:
raise Exception("file hash doesn't match for %s: %s != %s" % (path, fileHash, h.hexdigest()))

if 'main/dep11/README' not in pathsSeen:
raise Exception("README file not included in release file")

0 comments on commit 3fc792b

Please sign in to comment.