1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-13 01:20:24 +02:00

add sfdisk tests

This commit is contained in:
Kelly Brazil
2021-06-30 16:54:34 -07:00
parent 5321a15dcf
commit 3d78692c59
11 changed files with 150 additions and 1 deletions

View File

@ -0,0 +1 @@
[{"disk":"/dev/sda","units":"sectors","partitions":[{"device":"/dev/sda1","start":2048,"size":2097152,"id":"83","boot":true},{"device":"/dev/sda2","start":2099200,"size":39843840,"id":"8e","boot":false},{"device":"/dev/sda3","start":0,"size":0,"id":"0","boot":false},{"device":"/dev/sda4","start":0,"size":0,"id":"0","boot":false}]},{"disk":"/dev/sdb","units":"sectors","partitions":[{"device":"/dev/sdb1","start":2048,"size":2097152,"id":"83","boot":true},{"device":"/dev/sdb2","start":2099200,"size":39843840,"id":"8e","boot":false},{"device":"/dev/sdb3","start":0,"size":0,"id":"0","boot":false},{"device":"/dev/sdb4","start":0,"size":0,"id":"0","boot":false}]}]

View File

@ -0,0 +1,16 @@
# partition table of /dev/sda
unit: sectors
/dev/sda1 : start= 2048, size= 2097152, Id=83, bootable
/dev/sda2 : start= 2099200, size= 39843840, Id=8e
/dev/sda3 : start= 0, size= 0, Id= 0
/dev/sda4 : start= 0, size= 0, Id= 0
# partition table of /dev/sdb
unit: sectors
/dev/sdb1 : start= 2048, size= 2097152, Id=83, bootable
/dev/sdb2 : start= 2099200, size= 39843840, Id=8e
/dev/sdb3 : start= 0, size= 0, Id= 0
/dev/sdb4 : start= 0, size= 0, Id= 0

View File

@ -0,0 +1 @@
[{"disk":"/dev/sda","units":"sectors","partitions":[{"device":"/dev/sda1","start":2048,"size":2097152,"id":"83","boot":true},{"device":"/dev/sda2","start":2099200,"size":39843840,"id":"8e","boot":false},{"device":"/dev/sda3","start":0,"size":0,"id":"0","boot":false},{"device":"/dev/sda4","start":0,"size":0,"id":"0","boot":false}]}]

View File

@ -5,4 +5,3 @@ unit: sectors
/dev/sda2 : start= 2099200, size= 39843840, Id=8e /dev/sda2 : start= 2099200, size= 39843840, Id=8e
/dev/sda3 : start= 0, size= 0, Id= 0 /dev/sda3 : start= 0, size= 0, Id= 0
/dev/sda4 : start= 0, size= 0, Id= 0 /dev/sda4 : start= 0, size= 0, Id= 0

View File

@ -0,0 +1 @@
[{"disk":"/dev/sda","cylinders":2610,"heads":255,"sectors_per_track":63,"units":"cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0","partitions":[{"device":"/dev/sda1","boot":true,"start":0,"end":130,"cyls":131,"blocks":1048576,"id":"83","system":"Linux"},{"device":"/dev/sda2","boot":false,"start":130,"end":2610,"cyls":2481,"blocks":19921920,"id":"8e","system":"Linux LVM"},{"device":"/dev/sda3","boot":false,"start":0,"end":null,"cyls":0,"blocks":0,"id":"0","system":"Empty"},{"device":"/dev/sda4","boot":false,"start":0,"end":null,"cyls":0,"blocks":0,"id":"0","system":"Empty"}]},{"disk":"/dev/mapper/centos-root","cylinders":2218,"heads":255,"sectors_per_track":63},{"disk":"/dev/mapper/centos-swap","cylinders":261,"heads":255,"sectors_per_track":63,"units":"cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0","partitions":[{"device":"/dev/sda1","boot":true,"start":0,"end":130,"cyls":131,"blocks":1048576,"id":"83","system":"Linux"},{"device":"/dev/sda2","boot":false,"start":130,"end":2610,"cyls":2481,"blocks":19921920,"id":"8e","system":"Linux LVM"},{"device":"/dev/sda3","boot":false,"start":0,"end":null,"cyls":0,"blocks":0,"id":"0","system":"Empty"},{"device":"/dev/sda4","boot":false,"start":0,"end":null,"cyls":0,"blocks":0,"id":"0","system":"Empty"}]}]

View File

@ -0,0 +1,21 @@
Disk /dev/sda: 2610 cylinders, 255 heads, 63 sectors/track
Units: cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0
Device Boot Start End #cyls #blocks Id System
/dev/sda1 * 0+ 130- 131- 1048576 83 Linux
/dev/sda2 130+ 2610- 2481- 19921920 8e Linux LVM
/dev/sda3 0 - 0 0 0 Empty
/dev/sda4 0 - 0 0 0 Empty
Disk /dev/mapper/centos-root: 2218 cylinders, 255 heads, 63 sectors/track
Disk /dev/mapper/centos-swap: 261 cylinders, 255 heads, 63 sectors/track
Units: cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0
Device Boot Start End #cyls #blocks Id System
/dev/sda1 * 0+ 130- 131- 1048576 83 Linux
/dev/sda2 130+ 2610- 2481- 19921920 8e Linux LVM
/dev/sda3 0 - 0 0 0 Empty
/dev/sda4 0 - 0 0 0 Empty

View File

@ -0,0 +1 @@
[{"disk":"/dev/sda","cylinders":2610,"heads":255,"sectors_per_track":63,"units":"cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0","partitions":[{"device":"/dev/sda1","boot":true,"start":0,"end":130,"cyls":131,"blocks":1048576,"id":"83","system":"Linux"},{"device":"/dev/sda2","boot":false,"start":130,"end":2610,"cyls":2481,"blocks":19921920,"id":"8e","system":"Linux LVM"},{"device":"/dev/sda3","boot":false,"start":0,"end":null,"cyls":0,"blocks":0,"id":"0","system":"Empty"},{"device":"/dev/sda4","boot":false,"start":0,"end":null,"cyls":0,"blocks":0,"id":"0","system":"Empty"}]},{"disk":"/dev/mapper/centos-root","cylinders":2218,"heads":255,"sectors_per_track":63},{"disk":"/dev/mapper/centos-swap","cylinders":261,"heads":255,"sectors_per_track":63}]

View File

@ -0,0 +1 @@
[{"disk":"/dev/sda","cylinders":2610,"heads":255,"sectors_per_track":63,"units":"blocks of 1024 bytes, counting from 0","partitions":[{"device":"/dev/sda1","boot":true,"start":1024,"end":1049599,"blocks":1048576,"id":"83","system":"Linux"},{"device":"/dev/sda2","boot":false,"start":1049600,"end":20971519,"blocks":19921920,"id":"8e","system":"Linux LVM"},{"device":"/dev/sda3","boot":false,"start":0,"end":null,"blocks":0,"id":"0","system":"Empty"},{"device":"/dev/sda4","boot":false,"start":0,"end":null,"blocks":0,"id":"0","system":"Empty"}]},{"disk":"/dev/mapper/centos-root","cylinders":2218,"heads":255,"sectors_per_track":63},{"disk":"/dev/mapper/centos-swap","cylinders":261,"heads":255,"sectors_per_track":63}]

View File

@ -0,0 +1 @@
[{"disk":"/dev/sda","cylinders":2610,"heads":255,"sectors_per_track":63,"units":"1MiB = 1024*1024 bytes, blocks of 1024 bytes, counting from 0","partitions":[{"device":"/dev/sda1","boot":true,"start":1,"end":1024,"mib":1024,"blocks":1048576,"id":"83","system":"Linux"},{"device":"/dev/sda2","boot":false,"start":1025,"end":20479,"mib":19455,"blocks":19921920,"id":"8e","system":"Linux LVM"},{"device":"/dev/sda3","boot":false,"start":0,"end":null,"mib":0,"blocks":0,"id":"0","system":"Empty"},{"device":"/dev/sda4","boot":false,"start":0,"end":null,"mib":0,"blocks":0,"id":"0","system":"Empty"}]},{"disk":"/dev/mapper/centos-root","cylinders":2218,"heads":255,"sectors_per_track":63},{"disk":"/dev/mapper/centos-swap","cylinders":261,"heads":255,"sectors_per_track":63}]

View File

@ -0,0 +1 @@
[{"disk":"/dev/sda","cylinders":2610,"heads":255,"sectors_per_track":63,"units":"sectors of 512 bytes, counting from 0","partitions":[{"device":"/dev/sda1","boot":true,"start":2048,"end":2099199,"sectors":2097152,"id":"83","system":"Linux"},{"device":"/dev/sda2","boot":false,"start":2099200,"end":41943039,"sectors":39843840,"id":"8e","system":"Linux LVM"},{"device":"/dev/sda3","boot":false,"start":0,"end":null,"sectors":0,"id":"0","system":"Empty"},{"device":"/dev/sda4","boot":false,"start":0,"end":null,"sectors":0,"id":"0","system":"Empty"}]},{"disk":"/dev/mapper/centos-root","cylinders":2218,"heads":255,"sectors_per_track":63},{"disk":"/dev/mapper/centos-swap","cylinders":261,"heads":255,"sectors_per_track":63}]

106
tests/test_sfdisk.py Normal file
View File

@ -0,0 +1,106 @@
import os
import json
import unittest
import jc.parsers.sfdisk
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
def setUp(self):
# input
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-l.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_sfdisk_l = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-l-multi.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_sfdisk_l_multi = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-d.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_sfdisk_d = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-d-multi.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_sfdisk_d_multi = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-luB.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_sfdisk_luB = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-luM.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_sfdisk_luM = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-luS.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_sfdisk_luS = f.read()
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-l.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_sfdisk_l_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-l-multi.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_sfdisk_l_multi_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-d.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_sfdisk_d_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-d-multi.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_sfdisk_d_multi_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-luB.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_sfdisk_luB_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-luM.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_sfdisk_luM_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/sfdisk-luS.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_sfdisk_luS_json = json.loads(f.read())
def test_sfdisk_nodata(self):
"""
Test 'sfdisk' with no data
"""
self.assertEqual(jc.parsers.sfdisk.parse('', quiet=True), [])
def test_sfdisk_l_centos_7_7(self):
"""
Test 'sfdisk -l' on Centos 7.7
"""
self.assertEqual(jc.parsers.sfdisk.parse(self.centos_7_7_sfdisk_l, quiet=True), self.centos_7_7_sfdisk_l_json)
def test_sfdisk_l_multi_centos_7_7(self):
"""
Test 'sfdisk -l' with multiple disk data on Centos 7.7
"""
self.assertEqual(jc.parsers.sfdisk.parse(self.centos_7_7_sfdisk_l_multi, quiet=True), self.centos_7_7_sfdisk_l_multi_json)
def test_sfdisk_d_centos_7_7(self):
"""
Test 'sfdisk -d' on Centos 7.7
"""
self.assertEqual(jc.parsers.sfdisk.parse(self.centos_7_7_sfdisk_d, quiet=True), self.centos_7_7_sfdisk_d_json)
def test_sfdisk_d_multi_centos_7_7(self):
"""
Test 'sfdisk -d' with multiple disk data on Centos 7.7
"""
self.assertEqual(jc.parsers.sfdisk.parse(self.centos_7_7_sfdisk_d_multi, quiet=True), self.centos_7_7_sfdisk_d_multi_json)
def test_sfdisk_luB_centos_7_7(self):
"""
Test 'sfdisk -luB' on Centos 7.7
"""
self.assertEqual(jc.parsers.sfdisk.parse(self.centos_7_7_sfdisk_luB, quiet=True), self.centos_7_7_sfdisk_luB_json)
def test_sfdisk_luM_centos_7_7(self):
"""
Test 'sfdisk -luM' on Centos 7.7
"""
self.assertEqual(jc.parsers.sfdisk.parse(self.centos_7_7_sfdisk_luM, quiet=True), self.centos_7_7_sfdisk_luM_json)
def test_sfdisk_luS_centos_7_7(self):
"""
Test 'sfdisk -luS' on Centos 7.7
"""
self.assertEqual(jc.parsers.sfdisk.parse(self.centos_7_7_sfdisk_luS, quiet=True), self.centos_7_7_sfdisk_luS_json)
if __name__ == '__main__':
unittest.main()