disk: use bytes instead of sectors in all code
Use bytes internally everywhere and convert to sectors only when writing the options for the stages. Changed the AlignUp() method to not do the alignment if the input is already aligned. This changes the behaviour when the size is 0, but that's not a realistic use case. Updated unit tests to match. Manifests are unaffected. Co-Authored-By: Christian Kellner <christian@kellner.me>
This commit is contained in:
parent
abaadf95ed
commit
dec5a3850c
15 changed files with 115 additions and 113 deletions
|
|
@ -12,20 +12,23 @@ import (
|
|||
func TestDisk_AlignUp(t *testing.T) {
|
||||
|
||||
pt := disk.PartitionTable{}
|
||||
firstAligned := pt.BytesToSectors(disk.DefaultGrainBytes)
|
||||
firstAligned := disk.DefaultGrainBytes
|
||||
|
||||
tests := []struct {
|
||||
size uint64
|
||||
want uint64
|
||||
}{
|
||||
{0, firstAligned},
|
||||
{0, 0},
|
||||
{1, firstAligned},
|
||||
{firstAligned - 1, firstAligned},
|
||||
{firstAligned, firstAligned}, // grain is already aligned => no change
|
||||
{firstAligned / 2, firstAligned},
|
||||
{firstAligned + 1, firstAligned * 2},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
got := pt.AlignUp(tt.size)
|
||||
assert.Equal(t, tt.want, got)
|
||||
assert.Equal(t, tt.want, got, "Expected %d, got %d", tt.want, got)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue