~jamesodhunt/ubuntu/vivid/ubuntu-core-upgrader/handle-invalid-removed-file

« back to all changes in this revision

Viewing changes to functional/test_upgrader.py

  • Committer: James Hunt
  • Date: 2015-03-27 11:10:37 UTC
  • Revision ID: james.hunt@ubuntu.com-20150327111037-azko3hhoco08mu7a
functional/test_upgrader.py: Add tests for an invalid removed file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
595
595
        self.assertTrue(is_sym_link_broken(victim_link_file_path))
596
596
 
597
597
 
 
598
class UpgraderMiscTests(UbuntuCoreUpgraderTestCase):
 
599
 
 
600
    def common_removed_file_test(self, contents):
 
601
        '''
 
602
        Common code to test for an invalid removed file.
 
603
 
 
604
        The contents parameter specifies the contents of the removed
 
605
        file.
 
606
        '''
 
607
        file = 'created-regular-file'
 
608
 
 
609
        create_file(self.update.removed_file, contents)
 
610
 
 
611
        file_path = os.path.join(self.update.system_dir, file)
 
612
        create_file(file_path, 'foo bar')
 
613
 
 
614
        archive = self.update.create_archive(self.TARFILE)
 
615
        self.assertTrue(os.path.exists(archive))
 
616
 
 
617
        cmd_file = os.path.join(self.update.tmp_dir, CMD_FILE)
 
618
        make_command_file(cmd_file, [self.TARFILE])
 
619
 
 
620
        file_path = os.path.join(self.victim_dir, file)
 
621
        self.assertFalse(os.path.exists(file_path))
 
622
 
 
623
        # XXX: There is an implicit test here since if the upgrader
 
624
        # fails (as documented on LP: #1437225), this test will also
 
625
        # fail.
 
626
        call_upgrader(cmd_file, self.victim_dir, self.update)
 
627
 
 
628
        self.assertTrue(os.path.exists(file_path))
 
629
 
 
630
        # ensure the empty removed file hasn't removed the directory the
 
631
        # unpack applies to.
 
632
        self.assertTrue(self.victim_dir)
 
633
 
 
634
    def test_removed_file_empty(self):
 
635
        '''
 
636
        Ensure the upgrader ignores an empty 'removed' file.
 
637
        '''
 
638
        self.common_removed_file_test('')
 
639
 
 
640
    def test_removed_file_space(self):
 
641
        '''
 
642
        Ensure the upgrader handles a 'removed' file containing just a
 
643
        space.
 
644
        '''
 
645
        self.common_removed_file_test(' ')
 
646
 
 
647
    def test_removed_file_nl(self):
 
648
        '''
 
649
        Ensure the upgrader handles a 'removed' file containing just a
 
650
        newline
 
651
        '''
 
652
        self.common_removed_file_test('\n')
 
653
 
 
654
 
598
655
def main():
599
656
    kwargs = {}
600
657
    format =             \