-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
disk: add tests for PartitionTableType and FSType enums
- Loading branch information
1 parent
78d183f
commit 831d4a4
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package disk_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/osbuild/images/pkg/disk" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestEnumPartitionTableType(t *testing.T) { | ||
enumMap := map[string]disk.PartitionTableType{ | ||
"": disk.PT_NONE, | ||
"dos": disk.PT_DOS, | ||
"gpt": disk.PT_GPT, | ||
} | ||
|
||
assert := assert.New(t) | ||
for name, num := range enumMap { | ||
ptt, err := disk.NewPartitionTableType(name) | ||
expected := disk.PartitionTableType(num) | ||
|
||
assert.NoError(err) | ||
assert.Equal(expected, ptt) | ||
|
||
assert.Equal(name, ptt.String()) | ||
} | ||
|
||
// error test: bad value | ||
badPtt := disk.PartitionTableType(3) | ||
assert.PanicsWithValue("unknown or unsupported partition table type with enum value 3", func() { _ = badPtt.String() }) | ||
|
||
// error test: bad name | ||
_, err := disk.NewPartitionTableType("not-a-type") | ||
assert.EqualError(err, "unknown or unsupported partition table type name: not-a-type") | ||
} | ||
|
||
func TestEnumFSType(t *testing.T) { | ||
enumMap := map[string]disk.FSType{ | ||
"": disk.FS_NONE, | ||
"vfat": disk.FS_VFAT, | ||
"ext4": disk.FS_EXT4, | ||
"xfs": disk.FS_XFS, | ||
"btrfs": disk.FS_BTRFS, | ||
} | ||
|
||
assert := assert.New(t) | ||
for name, num := range enumMap { | ||
fst, err := disk.NewFSType(name) | ||
expected := disk.FSType(num) | ||
|
||
assert.NoError(err) | ||
assert.Equal(expected, fst) | ||
|
||
assert.Equal(name, fst.String()) | ||
} | ||
|
||
// error test: bad value | ||
badFst := disk.FSType(5) | ||
assert.PanicsWithValue("unknown or unsupported filesystem type with enum value 5", func() { _ = badFst.String() }) | ||
|
||
// error test: bad name | ||
_, err := disk.NewFSType("not-a-type") | ||
assert.EqualError(err, "unknown or unsupported filesystem type name: not-a-type") | ||
} |