summaryrefslogtreecommitdiff
path: root/morphlib/morphologyfactory_tests.py
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-07-18 16:34:56 +0100
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-07-18 17:29:59 +0100
commitb068b7fa1331a7c6e2ef0632d9566310bfa58b9d (patch)
treea5ba4624e87860920059cc4a4b931c75a5b5d778 /morphlib/morphologyfactory_tests.py
parent0a1c41a539adee00cf4eefa81d4ab8841b65b10f (diff)
downloadmorph-b068b7fa1331a7c6e2ef0632d9566310bfa58b9d.tar.gz
Have MorphologyFactory set Morphology.builds_artifacts
This way we can have one place in the code where we determine what artifacts get built from a specific morphology, rather than spreading the information around the code base. From now on, everything is supposed to use the builds_artifacts attribute to get the list of artifacts. ArtifactResolver has been changed to do that. Some of the tests are now a bit messier, and should really be changed to create Morphology objects using MorphologyFactory, but that's a change for another day.
Diffstat (limited to 'morphlib/morphologyfactory_tests.py')
-rw-r--r--morphlib/morphologyfactory_tests.py61
1 files changed, 60 insertions, 1 deletions
diff --git a/morphlib/morphologyfactory_tests.py b/morphlib/morphologyfactory_tests.py
index 11d53a19..89b66d02 100644
--- a/morphlib/morphologyfactory_tests.py
+++ b/morphlib/morphologyfactory_tests.py
@@ -37,8 +37,42 @@ class FakeRemoteRepoCache(object):
class FakeLocalRepo(object):
+ morphologies = {
+ 'chunk.morph': '''{
+ "name": "local-foo",
+ "kind": "chunk",
+ "build-system": "bar"
+ }''',
+ 'chunk-split.morph': '''{
+ "name": "local-foo",
+ "kind": "chunk",
+ "build-system": "bar",
+ "chunks": {
+ "local-foo-runtime": [],
+ "local-foo-devel": []
+ }
+ }''',
+ 'stratum.morph': '''{
+ "name": "foo-stratum",
+ "kind": "stratum"
+ }''',
+ 'system.morph': '''{
+ "name": "foo-system",
+ "kind": "system",
+ "arch": "%(arch)s"
+ }''',
+ }
+
+ def __init__(self):
+ self.arch = 'unknown'
+
def cat(self, sha1, filename):
- if filename.endswith('.morph'):
+ if filename in self.morphologies:
+ values = {
+ 'arch': self.arch,
+ }
+ return self.morphologies[filename] % values
+ elif filename.endswith('.morph'):
return '''{
"name": "local-foo",
"kind": "chunk",
@@ -138,3 +172,28 @@ class MorphologyFactoryTests(unittest.TestCase):
self.lrc.has_repo = self.doesnothaverepo
self.assertRaises(NotcachedError, self.lmf.get_morphology,
'reponame', 'sha1', 'unreached.morph')
+
+ def test_sets_builds_artifacts_for_simple_chunk(self):
+ morph = self.mf.get_morphology('reponame', 'sha1', 'chunk.morph')
+ self.assertEqual(morph.builds_artifacts, ['local-foo'])
+
+ def test_sets_builds_artifacts_for_split_chunk(self):
+ morph = self.mf.get_morphology('reponame', 'sha1', 'chunk-split.morph')
+ self.assertEqual(morph.builds_artifacts,
+ ['local-foo-runtime', 'local-foo-devel'])
+
+ def test_sets_builds_artifacts_for_artifact(self):
+ morph = self.mf.get_morphology('reponame', 'sha1', 'stratum.morph')
+ self.assertEqual(morph.builds_artifacts, ['foo-stratum'])
+
+ def test_sets_builds_artifacts_for_x86_64_system(self):
+ self.lr.arch = 'x86_64'
+ morph = self.mf.get_morphology('reponame', 'sha1', 'system.morph')
+ self.assertEqual(morph.builds_artifacts, ['foo-system-rootfs'])
+
+ def test_sets_builds_artifacts_for_arm_system(self):
+ self.lr.arch = 'arm'
+ morph = self.mf.get_morphology('reponame', 'sha1', 'system.morph')
+ self.assertEqual(sorted(morph.builds_artifacts),
+ sorted(['foo-system-rootfs', 'foo-system-kernel']))
+