replication_lib: Requre paths relative to the source root.
- It doesn't make sense to have the ReplicationConfig use
absolute paths, e.g. in the context of PUpr, it shouldn't
make assumptions on where the source is checked out. The
proto description already specifies that relative paths
should be used.
- Fix tests that were using absolute paths.
- The next CL will generate C files from the platform
config in the PUpr endpoint. This change is needed to
mock the call to cros_config_schema
BUG=chromium:1018294
TEST=run_tests
Change-Id: I2fe5994506171b540c9c7185d02f7d83beb64c38
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/1950709
Tested-by: Andrew Lamb <andrewlamb@chromium.org>
Commit-Queue: Andrew Lamb <andrewlamb@chromium.org>
Reviewed-by: David Burger <dburger@chromium.org>
diff --git a/scripts/replication_util_unittest.py b/scripts/replication_util_unittest.py
index 071af11..c09f45c 100644
--- a/scripts/replication_util_unittest.py
+++ b/scripts/replication_util_unittest.py
@@ -15,6 +15,7 @@
from chromite.api.gen.config.replication_config_pb2 import (
ReplicationConfig, FileReplicationRule, FILE_TYPE_OTHER,
REPLICATION_TYPE_COPY)
+from chromite.lib import constants
from chromite.lib import cros_test_lib
from chromite.lib import osutils
from chromite.scripts import replication_util
@@ -22,7 +23,7 @@
D = cros_test_lib.Directory
-class RunTest(cros_test_lib.TempDirTestCase):
+class RunTest(cros_test_lib.MockTempDirTestCase):
"""Tests of the run command.
Note that detailed tests of replication behavior should be done in
@@ -33,12 +34,14 @@
file_layout = (D('src', ['audio_file']),)
cros_test_lib.CreateOnDiskHierarchy(self.tempdir, file_layout)
- self.audio_path = os.path.join(self.tempdir, 'src', 'audio_file')
- osutils.WriteFile(self.audio_path, '[Speaker A Settings]')
+ self.audio_path = os.path.join('src', 'audio_file')
+ self.WriteTempFile(self.audio_path, '[Speaker A Settings]')
+
+ self.PatchObject(constants, 'SOURCE_ROOT', new=self.tempdir)
def testRun(self):
"""Basic test of the 'run' command."""
- audio_dst_path = os.path.join(self.tempdir, 'dst', 'audio_file')
+ audio_dst_path = os.path.join('dst', 'audio_file')
replication_config = ReplicationConfig(file_replication_rules=[
FileReplicationRule(
@@ -64,11 +67,11 @@
cros_test_lib.VerifyOnDiskHierarchy(self.tempdir, expected_file_layout)
- self.assertFileContents(audio_dst_path, '[Speaker A Settings]')
+ self.assertTempFileContents(audio_dst_path, '[Speaker A Settings]')
def testUnknownFieldInConfig(self):
"""Test that unknown fields in the ReplicationConfig cause an error."""
- audio_dst_path = os.path.join(self.tempdir, 'dst', 'audio_file')
+ audio_dst_path = os.path.join('dst', 'audio_file')
replication_config = ReplicationConfig(file_replication_rules=[
FileReplicationRule(