summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Coldrick <adam.coldrick@codethink.co.uk>2014-06-30 11:31:49 +0000
committerAdam Coldrick <adam.coldrick@codethink.co.uk>2014-07-04 08:35:25 +0000
commit30b23f51e4d85f265dbff8d0bb0ed7fce9f68606 (patch)
tree514fceefd8d0155b0e811cfa9c51001ce9fd7382
parent8f16426f64107169d7387b8262b072089f14e4b0 (diff)
downloadmorph-30b23f51e4d85f265dbff8d0bb0ed7fce9f68606.tar.gz
unittests: Test that paths in the morph field of chunks work
This commit adds a test to check that having a filepath in the morph field of a chunk spec works as expected. It also fixes the tests to work with a separate morphology repository and source repository in Source objects.
-rw-r--r--morphlib/artifact_tests.py3
-rw-r--r--morphlib/artifactresolver_tests.py105
-rw-r--r--morphlib/cachekeycomputer_tests.py8
-rw-r--r--morphlib/localartifactcache_tests.py3
-rw-r--r--morphlib/remoteartifactcache_tests.py3
-rw-r--r--morphlib/source_tests.py6
6 files changed, 96 insertions, 32 deletions
diff --git a/morphlib/artifact_tests.py b/morphlib/artifact_tests.py
index d4b15cba..9b796849 100644
--- a/morphlib/artifact_tests.py
+++ b/morphlib/artifact_tests.py
@@ -42,7 +42,8 @@ class ArtifactTests(unittest.TestCase):
}
''')
self.source = morphlib.source.Source(
- 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph,
+ 'chunk.morph', 'repo', 'ref')
self.artifact_name = 'chunk-runtime'
self.artifact = morphlib.artifact.Artifact(
self.source, self.artifact_name)
diff --git a/morphlib/artifactresolver_tests.py b/morphlib/artifactresolver_tests.py
index 6f62b4d1..777cf34b 100644
--- a/morphlib/artifactresolver_tests.py
+++ b/morphlib/artifactresolver_tests.py
@@ -110,7 +110,8 @@ class ArtifactResolverTests(unittest.TestCase):
morph = FakeChunkMorphology('chunk')
source = morphlib.source.Source(
- 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'chunk.morph')
pool.add(source)
artifacts = self.resolver.resolve_artifacts(pool)
@@ -129,7 +130,8 @@ class ArtifactResolverTests(unittest.TestCase):
morph = FakeChunkMorphology('chunk', ['chunk-foobar'])
source = morphlib.source.Source(
- 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'chunk.morph')
pool.add(source)
artifacts = self.resolver.resolve_artifacts(pool)
@@ -147,7 +149,8 @@ class ArtifactResolverTests(unittest.TestCase):
morph = FakeChunkMorphology('chunk', ['chunk-baz', 'chunk-qux'])
source = morphlib.source.Source(
- 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'chunk.morph')
pool.add(source)
artifacts = self.resolver.resolve_artifacts(pool)
@@ -167,13 +170,51 @@ class ArtifactResolverTests(unittest.TestCase):
morph = FakeChunkMorphology('chunk')
chunk = morphlib.source.Source(
- 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'chunk.morph')
pool.add(chunk)
morph = FakeStratumMorphology(
'stratum', chunks=[('chunk', 'chunk', 'repo', 'ref')])
stratum = morphlib.source.Source(
- 'repo', 'ref', 'sha1', 'tree', morph, 'stratum.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'stratum.morph')
+ pool.add(stratum)
+
+ artifacts = self.resolver.resolve_artifacts(pool)
+
+ self.assertEqual(len(artifacts),
+ sum(len(s.split_rules.artifacts) for s in pool))
+
+ stratum_artifacts = set(a for a in artifacts if a.source == stratum)
+ chunk_artifacts = set(a for a in artifacts if a.source == chunk)
+
+ for stratum_artifact in stratum_artifacts:
+ self.assertTrue(stratum_artifact.name.startswith('stratum'))
+ self.assertEqual(stratum_artifact.dependents, [])
+ self.assertTrue(any(dep in chunk_artifacts
+ for dep in stratum_artifact.dependencies))
+
+ for chunk_artifact in chunk_artifacts:
+ self.assertTrue(chunk_artifact.name.startswith('chunk'))
+ self.assertEqual(chunk_artifact.dependencies, [])
+ self.assertTrue(any(dep in stratum_artifacts
+ for dep in chunk_artifact.dependents))
+
+ def test_resolve_stratum_and_chunk_with_chunk_path(self):
+ pool = morphlib.sourcepool.SourcePool()
+
+ morph = FakeChunkMorphology('chunk')
+ chunk = morphlib.source.Source(
+ 'repo', 'ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'chunk.morph')
+ pool.add(chunk)
+
+ morph = FakeStratumMorphology(
+ 'stratum', chunks=[('chunk', 'chunk.morph', 'repo', 'ref')])
+ stratum = morphlib.source.Source(
+ 'repo', 'ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'stratum.morph')
pool.add(stratum)
artifacts = self.resolver.resolve_artifacts(pool)
@@ -201,7 +242,8 @@ class ArtifactResolverTests(unittest.TestCase):
morph = FakeChunkMorphology('chunk', ['chunk-foo', 'chunk-bar'])
chunk = morphlib.source.Source(
- 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'chunk.morph')
pool.add(chunk)
morph = FakeStratumMorphology(
@@ -210,7 +252,8 @@ class ArtifactResolverTests(unittest.TestCase):
('chunk', 'chunk', 'repo', 'ref'),
])
stratum = morphlib.source.Source(
- 'repo', 'ref', 'sha1', 'tree', morph, 'stratum.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'stratum.morph')
pool.add(stratum)
artifacts = self.resolver.resolve_artifacts(pool)
@@ -238,14 +281,16 @@ class ArtifactResolverTests(unittest.TestCase):
morph = FakeChunkMorphology('chunk1')
chunk1 = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk1.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'chunk1.morph')
pool.add(chunk1)
morph = FakeStratumMorphology(
'stratum1',
chunks=[('chunk1', 'chunk1', 'repo', 'original/ref')])
stratum1 = morphlib.source.Source(
- 'repo', 'ref', 'sha1', 'tree', morph, 'stratum1.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'stratum1.morph')
pool.add(stratum1)
morph = morphlib.morph2.Morphology(
@@ -269,12 +314,14 @@ class ArtifactResolverTests(unittest.TestCase):
''')
morph.builds_artifacts = ['system-rootfs']
system = morphlib.source.Source(
- 'repo', 'ref', 'sha1', 'tree', morph, 'system.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'system.morph')
pool.add(system)
morph = FakeChunkMorphology('chunk2')
chunk2 = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk2.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'chunk2.morph')
pool.add(chunk2)
morph = FakeStratumMorphology(
@@ -282,7 +329,8 @@ class ArtifactResolverTests(unittest.TestCase):
chunks=[('chunk2', 'chunk2', 'repo', 'original/ref')],
build_depends=[('stratum1', 'repo', 'ref')])
stratum2 = morphlib.source.Source(
- 'repo', 'ref', 'sha1', 'tree', morph, 'stratum2.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'stratum2.morph')
pool.add(stratum2)
artifacts = self.resolver.resolve_artifacts(pool)
@@ -369,22 +417,26 @@ class ArtifactResolverTests(unittest.TestCase):
''')
morph.builds_artifacts = ['stratum']
stratum = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'stratum.morph')
pool.add(stratum)
morph = FakeChunkMorphology('chunk1')
chunk1 = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk1.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'chunk1.morph')
pool.add(chunk1)
morph = FakeChunkMorphology('chunk2')
chunk2 = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk2.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'chunk2.morph')
pool.add(chunk2)
morph = FakeChunkMorphology('chunk3')
chunk3 = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk3.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'chunk3.morph')
pool.add(chunk3)
artifacts = self.resolver.resolve_artifacts(pool)
@@ -425,7 +477,8 @@ class ArtifactResolverTests(unittest.TestCase):
chunks=[],
build_depends=[('stratum2', 'repo', 'original/ref')])
stratum1 = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum1.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'stratum1.morph')
pool.add(stratum1)
morph = FakeStratumMorphology(
@@ -433,7 +486,8 @@ class ArtifactResolverTests(unittest.TestCase):
chunks=[],
build_depends=[('stratum1', 'repo', 'original/ref')])
stratum2 = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum2.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'stratum2.morph')
pool.add(stratum2)
self.assertRaises(morphlib.artifactresolver.MutualDependencyError,
@@ -466,17 +520,20 @@ class ArtifactResolverTests(unittest.TestCase):
''')
morph.builds_artifacts = ['stratum']
stratum = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'stratum.morph')
pool.add(stratum)
morph = FakeChunkMorphology('chunk1')
chunk1 = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk1.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'chunk1.morph')
pool.add(chunk1)
morph = FakeChunkMorphology('chunk2')
chunk2 = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk2.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'chunk2.morph')
pool.add(chunk2)
self.assertRaises(morphlib.artifactresolver.DependencyOrderError,
@@ -502,12 +559,14 @@ class ArtifactResolverTests(unittest.TestCase):
''')
morph.builds_artifacts = ['stratum']
stratum = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', 'tree', morph, 'stratum.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'stratum.morph')
pool.add(stratum)
morph = FakeChunkMorphology('chunk')
chunk = morphlib.source.Source(
- 'repo', 'original/ref', 'sha1', 'tree', morph, 'chunk.morph')
+ 'repo', 'original/ref', 'sha1', 'tree', morph,
+ 'repo', 'ref', 'chunk.morph')
pool.add(chunk)
self.assertRaises(morphlib.artifactresolver.DependencyFormatError,
diff --git a/morphlib/cachekeycomputer_tests.py b/morphlib/cachekeycomputer_tests.py
index 9e18b19d..b504d0ca 100644
--- a/morphlib/cachekeycomputer_tests.py
+++ b/morphlib/cachekeycomputer_tests.py
@@ -98,7 +98,8 @@ class CacheKeyComputerTests(unittest.TestCase):
}.iteritems():
source = morphlib.source.Source(
'repo', 'original/ref', 'sha', 'tree',
- morphlib.morph2.Morphology(text), name)
+ morphlib.morph2.Morphology(text), 'repo',
+ 'original/ref', name)
self.source_pool.add(source)
# FIXME: This should use MorphologyFactory
m = source.morphology
@@ -182,7 +183,8 @@ class CacheKeyComputerTests(unittest.TestCase):
old_artifact = self._find_artifact('system-rootfs')
morphology = old_artifact.source.morphology
new_source = morphlib.source.Source('repo', 'original/ref', 'newsha',
- 'tree', morphology,
+ 'tree', morphology, 'repo',
+ 'original/ref',
old_artifact.source.filename)
sp = morphlib.sourcepool.SourcePool()
for source in self.source_pool:
@@ -204,7 +206,7 @@ class CacheKeyComputerTests(unittest.TestCase):
def test_same_morphology_added_to_source_pool_only_appears_once(self):
m = morphlib.morph2.Morphology('{"name": "chunk", "kind": "chunk"}')
src = morphlib.source.Source('repo', 'original/ref', 'sha', 'tree', m,
- 'chunk.morph')
+ 'repo', 'original/ref', 'chunk.morph')
sp = morphlib.sourcepool.SourcePool()
sp.add(src)
sp.add(src)
diff --git a/morphlib/localartifactcache_tests.py b/morphlib/localartifactcache_tests.py
index f400a645..d02ba3db 100644
--- a/morphlib/localartifactcache_tests.py
+++ b/morphlib/localartifactcache_tests.py
@@ -46,7 +46,8 @@ class LocalArtifactCacheTests(unittest.TestCase):
}
''')
self.source = morphlib.source.Source(
- 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph,
+ 'chunk.morph', 'repo', 'ref')
self.runtime_artifact = morphlib.artifact.Artifact(
self.source, 'chunk-runtime')
self.runtime_artifact.cache_key = '0'*64
diff --git a/morphlib/remoteartifactcache_tests.py b/morphlib/remoteartifactcache_tests.py
index d11bf264..ed97ad68 100644
--- a/morphlib/remoteartifactcache_tests.py
+++ b/morphlib/remoteartifactcache_tests.py
@@ -46,7 +46,8 @@ class RemoteArtifactCacheTests(unittest.TestCase):
}
''')
self.source = morphlib.source.Source(
- 'repo', 'ref', 'sha1', 'tree', morph, 'chunk.morph')
+ 'repo', 'ref', 'sha1', 'tree', morph,
+ 'chunk.morph', 'repo', 'ref')
self.runtime_artifact = morphlib.artifact.Artifact(
self.source, 'chunk-runtime')
self.runtime_artifact.cache_key = 'CHUNK-RUNTIME'
diff --git a/morphlib/source_tests.py b/morphlib/source_tests.py
index 6643f0fc..b8b8b8a5 100644
--- a/morphlib/source_tests.py
+++ b/morphlib/source_tests.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012 Codethink Limited
+# Copyright (C) 2012-2014 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -37,10 +37,10 @@ class SourceTests(unittest.TestCase):
self.filename = 'foo.morph'
self.source = morphlib.source.Source(
self.repo_name, self.original_ref, self.sha1, self.tree,
- self.morphology, self.filename)
+ self.morphology, self.repo_name, self.original_ref, self.filename)
self.other = morphlib.source.Source(
self.repo_name, self.original_ref, self.sha1, self.tree,
- self.morphology, self.filename)
+ self.morphology, self.repo_name, self.original_ref, self.filename)
def test_sets_repo_name(self):
self.assertEqual(self.source.repo_name, self.repo_name)