Skip to content

Commit

Permalink
tests: Move 'test_labels' to unit tests
Browse files Browse the repository at this point in the history
We don't need to run these tests as root.
  • Loading branch information
vojtechtrefny committed Jan 25, 2024
1 parent 8934f91 commit 808a65f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 39 deletions.
39 changes: 0 additions & 39 deletions tests/storage_tests/formats_test/labeling_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import unittest

from blivet.formats import device_formats
from blivet.size import Size
import blivet.formats.fs as fs
import blivet.formats.swap as swap
Expand All @@ -9,42 +6,6 @@
from . import fslabeling


class InitializationTestCase(unittest.TestCase):

"""Test FS object initialization."""

def test_labels(self):
"""Initialize some filesystems with valid and invalid labels."""

# Ext2FS has a maximum length of 16
self.assertFalse(fs.Ext2FS().label_format_ok("root___filesystem"))
self.assertTrue(fs.Ext2FS().label_format_ok("root__filesystem"))

# FATFS has a maximum length of 11
self.assertFalse(fs.FATFS().label_format_ok("rtfilesystem"))
self.assertTrue(fs.FATFS().label_format_ok("rfilesystem"))

# XFS has a maximum length 12 and does not allow spaces
self.assertFalse(fs.XFS().label_format_ok("root_filesyst"))
self.assertFalse(fs.XFS().label_format_ok("root file"))
self.assertTrue(fs.XFS().label_format_ok("root_filesys"))

# HFSPlus has a maximum length of 128, minimum length of 1, and does not allow colons
self.assertFalse(fs.HFSPlus().label_format_ok("n" * 129))
self.assertFalse(fs.HFSPlus().label_format_ok("root:file"))
self.assertFalse(fs.HFSPlus().label_format_ok(""))
self.assertTrue(fs.HFSPlus().label_format_ok("n" * 128))

# NTFS has a maximum length of 128
self.assertFalse(fs.NTFS().label_format_ok("n" * 129))
self.assertTrue(fs.NTFS().label_format_ok("n" * 128))

# all devices are permitted to be passed a label argument of None
# some will ignore it completely
for _k, v in device_formats.items():
self.assertIsNotNone(v(label=None))


class XFSTestCase(fslabeling.CompleteLabelingAsRoot):
_fs_class = fs.XFS
_invalid_label = "root filesystem"
Expand Down
36 changes: 36 additions & 0 deletions tests/unit_tests/formats_tests/init_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,39 @@ def test_formats_methods(self):
# Copy or deepcopy should preserve the id
self.assertEqual(ids, [copy.copy(obj).id for obj in objs])
self.assertEqual(ids, [copy.deepcopy(obj).id for obj in objs])


class InitializationTestCase(unittest.TestCase):

"""Test FS object initialization."""

def test_labels(self):
"""Initialize some filesystems with valid and invalid labels."""

# Ext2FS has a maximum length of 16
self.assertFalse(formats.fs.Ext2FS().label_format_ok("root___filesystem"))
self.assertTrue(formats.fs.Ext2FS().label_format_ok("root__filesystem"))

# FATFS has a maximum length of 11
self.assertFalse(formats.fs.FATFS().label_format_ok("rtfilesystem"))
self.assertTrue(formats.fs.FATFS().label_format_ok("rfilesystem"))

# XFS has a maximum length 12 and does not allow spaces
self.assertFalse(formats.fs.XFS().label_format_ok("root_filesyst"))
self.assertFalse(formats.fs.XFS().label_format_ok("root file"))
self.assertTrue(formats.fs.XFS().label_format_ok("root_filesys"))

# HFSPlus has a maximum length of 128, minimum length of 1, and does not allow colons
self.assertFalse(formats.fs.HFSPlus().label_format_ok("n" * 129))
self.assertFalse(formats.fs.HFSPlus().label_format_ok("root:file"))
self.assertFalse(formats.fs.HFSPlus().label_format_ok(""))
self.assertTrue(formats.fs.HFSPlus().label_format_ok("n" * 128))

# NTFS has a maximum length of 128
self.assertFalse(formats.fs.NTFS().label_format_ok("n" * 129))
self.assertTrue(formats.fs.NTFS().label_format_ok("n" * 128))

# all devices are permitted to be passed a label argument of None
# some will ignore it completely
for _k, v in formats.device_formats.items():
self.assertIsNotNone(v(label=None))

0 comments on commit 808a65f

Please sign in to comment.