예제 #1
0
 def test_build_untar_leading_dot(self):
     """
     Test build_untar with leading dot to tar -tf output
     """
     check_output_backup = subprocess.check_output
     tar_dotted = ''
     for line in TAR_OUT.split():
         tar_dotted += './{}\n'.format(line)
     tarball.subprocess.check_output = mock_gen(rv=tar_dotted)
     tarball.build.base_path = '.'
     self.assertEqual(
         tarball.build_untar('tarball/path'),
         ('tar --directory=. -xf tarball/path', 'libjpeg-turbo-1.5.1'))
예제 #2
0
    def test_build_untar(self):
        """
        Test build_untar using an array to test multiple cases.
        Case 1: Existent tar, with content and common dir.
        Case 2: Non existent tar.
        Case 3: Existent tar, but empty.
        Case 4: Existent tar, with content and non common dir.
        Case 5: Existent tar, with content, common dir with leading dot (./)
        Case 6: Existent tar, with content, one element only with (./)
        Case 7: Existent tar, with one single file
        """

        tests = (
            ({
                'is_tar': True,
                'content': ['dir/', 'dir/file1']
            }, ('tar --directory=. -xf path/tar_file-v1.tar', 'dir')),
            ({
                'is_tar': False,
                'content': []
            }, (False, False)),
            ({
                'is_tar': True,
                'content': []
            }, (False, False)),
            ({
                'is_tar': True,
                'content': ['dir/', 'dir1/file1']
            },
             ('tar --directory=. --one-top-level=tar_file-v1 -xf path/tar_file-v1.tar',
              '')),
            ({
                'is_tar': True,
                'content': ['./dir/', './dir/file1']
            }, ('tar --directory=. -xf path/tar_file-v1.tar', 'dir')),
            ({
                'is_tar': True,
                'content': ['./', './dir/', './dir1/file1']
            },
             ('tar --directory=. --one-top-level=tar_file-v1 -xf path/tar_file-v1.tar',
              '')),
            ({
                'is_tar': True,
                'content': ['file1']
            },
             ('tar --directory=. --one-top-level=tar_file-v1 -xf path/tar_file-v1.tar',
              None)),
        )
        global src_content

        for input, expected in tests:
            try:
                tarball.print_fatal = mock_gen(rv=None)
                tarball.tarfile.is_tarfile = mock_gen(rv=input['is_tar'])
                src_content = input['content']
                tarball.tarfile.open = MockSrcFile
                actual = tarball.build_untar('path/tar_file-v1.tar')
            except:
                actual = (False, False)
            finally:
                self.assertEqual(actual, expected)