Example #1
0
    def test_pull_rpm_must_not_clean_targets(self, mock_provision):
        rpm_source = sources.Rpm(self.rpm_file_path, self.dest_dir)
        rpm_source.pull()

        mock_provision.assert_called_once_with(
            self.dest_dir, clean_target=False, src=os.path.join(
                self.dest_dir, 'small-0.1-1.noarch.rpm'))
Example #2
0
    def test_pull_failure(self, mock_run):
        mock_run.side_effect = subprocess.CalledProcessError(1, [])

        rpm_source = sources.Rpm(self.rpm_file_path, self.dest_dir)
        raised = self.assertRaises(sources.errors.SnapcraftPullError, rpm_source.pull)
        self.assertThat(
            raised.command,
            MatchesRegex("rpm2cpio .*/dst/small-0.1-1.noarch.rpm | cpio -idmv"),
        )
        self.assertThat(raised.exit_code, Equals(1))
Example #3
0
    def test_pull_rpm_file_must_extract(self):
        rpm_file_name = 'test.rpm'
        dest_dir = 'src'
        os.makedirs(dest_dir)

        test_file_path = os.path.join(self.path, 'test.txt')
        open(test_file_path, 'w').close()
        rpm_file_path = os.path.join(self.path, rpm_file_name)
        os.chdir(self.path)
        with libarchive.file_writer(rpm_file_path, 'cpio', 'gzip') as rpm:
            rpm.add_files('test.txt')

        rpm_source = sources.Rpm(rpm_file_path, dest_dir)
        rpm_source.pull()

        self.assertEqual(os.listdir(dest_dir), ['test.txt'])
Example #4
0
    def test_extract_and_keep_rpmfile(self):
        rpm_file_name = 'test.rpm'
        dest_dir = 'src'
        os.makedirs(dest_dir)

        test_file_path = os.path.join(self.path, 'test.txt')
        open(test_file_path, 'w').close()
        rpm_file_path = os.path.join(self.path, rpm_file_name)
        os.chdir(self.path)
        with libarchive.file_writer(rpm_file_path, 'cpio', 'gzip') as rpm:
            rpm.add_files('test.txt')

        rpm_source = sources.Rpm(rpm_file_path, dest_dir)
        # This is the first step done by pull. We don't call pull to call the
        # second step with a different keep_rpm value.
        shutil.copy2(rpm_source.source, rpm_source.source_dir)
        rpm_source.provision(dst=dest_dir, keep_rpm=True)

        test_output_files = ['test.txt', rpm_file_name]
        self.assertCountEqual(os.listdir(dest_dir), test_output_files)
Example #5
0
    def test_pull_rpm_file_must_extract(self):
        rpm_source = sources.Rpm(self.rpm_file_path, self.dest_dir)
        rpm_source.pull()

        self.assertThat(os.path.join(self.dest_dir, 'bin', 'hello'),
                        FileExists())