diff options
3 files changed, 28 insertions, 8 deletions
diff --git a/native_client_sdk/src/build_tools/sdk_tools/command/update.py b/native_client_sdk/src/build_tools/sdk_tools/command/update.py index 29f84c8..e49765bb 100644 --- a/native_client_sdk/src/build_tools/sdk_tools/command/update.py +++ b/native_client_sdk/src/build_tools/sdk_tools/command/update.py @@ -383,7 +383,7 @@ def _GetFilenameFromURL(url): def _ValidateArchive(archive, actual_sha1, actual_size): if actual_size != archive.size: raise Error('Size mismatch on "%s". Expected %s but got %s bytes' % ( - archive.name, archive.size, actual_size)) + archive.url, archive.size, actual_size)) if actual_sha1 != archive.GetChecksum(): raise Error('SHA1 checksum mismatch on "%s". Expected %s but got %s' % ( - archive.name, archive.GetChecksum(), actual_sha1)) + archive.url, archive.GetChecksum(), actual_sha1)) diff --git a/native_client_sdk/src/build_tools/tests/sdktools_commands_test.py b/native_client_sdk/src/build_tools/tests/sdktools_commands_test.py index 8abef29..7dd9e61 100755 --- a/native_client_sdk/src/build_tools/tests/sdktools_commands_test.py +++ b/native_client_sdk/src/build_tools/tests/sdktools_commands_test.py @@ -285,6 +285,26 @@ class TestCommands(SdkToolsTestCase): self.assertTrue(os.path.exists( os.path.join(self.basedir, 'nacl_sdk', 'pepper_26', 'dummy2.txt'))) + def testUpdateBadSize(self): + """If an archive has a bad size, print an error. + """ + bundle = self._AddDummyBundle(self.manifest, 'pepper_26') + archive = bundle.GetHostOSArchive(); + archive.size = -1 + self._WriteManifest() + stdout = self._Run(['update', 'pepper_26'], expect_error=True) + self.assertTrue('Size mismatch' in stdout) + + def testUpdateBadSHA(self): + """If an archive has a bad SHA, print an error. + """ + bundle = self._AddDummyBundle(self.manifest, 'pepper_26') + archive = bundle.GetHostOSArchive(); + archive.checksum = 0 + self._WriteManifest() + stdout = self._Run(['update', 'pepper_26'], expect_error=True) + self.assertTrue('SHA1 checksum mismatch' in stdout) + def testUninstall(self): """The uninstall command should remove the installed bundle, if it exists. diff --git a/native_client_sdk/src/build_tools/tests/sdktools_test.py b/native_client_sdk/src/build_tools/tests/sdktools_test.py index d4987a1..71891f6 100755 --- a/native_client_sdk/src/build_tools/tests/sdktools_test.py +++ b/native_client_sdk/src/build_tools/tests/sdktools_test.py @@ -120,7 +120,7 @@ class SdkToolsTestCase(unittest.TestCase): archive.size = archive_size return archive - def _Run(self, args): + def _Run(self, args, expect_error=False): naclsdk_shell_script = os.path.join(self.basedir, 'nacl_sdk', 'naclsdk') if getos.GetPlatform() == 'win': naclsdk_shell_script += '.bat' @@ -129,11 +129,11 @@ class SdkToolsTestCase(unittest.TestCase): cmd.extend(['-U', self.server.GetURL(MANIFEST_BASENAME)]) process = subprocess.Popen(cmd, stdout=subprocess.PIPE) stdout, _ = process.communicate() - try: - self.assertEqual(process.returncode, 0) - except Exception: - print stdout - raise + + if ((expect_error and process.returncode == 0) or + (not expect_error and process.returncode != 0)): + self.fail('Error running nacl_sdk:\n"""\n%s\n"""' % stdout) + return stdout def _RunAndExtractRevision(self): |