diff --git a/pkg/block/block_linux.go b/pkg/block/block_linux.go index f43ccfd7..8be32595 100644 --- a/pkg/block/block_linux.go +++ b/pkg/block/block_linux.go @@ -233,7 +233,7 @@ func diskPartitions(ctx *context.Context, paths *linuxpath.Paths, disk string) [ if len(out) == 0 { size := partitionSizeBytes(paths, disk, "") mp, pt, ro := partitionInfo(paths, disk) - du := diskPartUUID(ctx, disk) + du := diskPartUUID(paths, disk, "") p := &Partition{ Name: disk, SizeBytes: size, diff --git a/pkg/block/block_linux_test.go b/pkg/block/block_linux_test.go index 98290e45..14299722 100644 --- a/pkg/block/block_linux_test.go +++ b/pkg/block/block_linux_test.go @@ -195,6 +195,28 @@ func TestDiskTypes(t *testing.T) { } } +func TestDiskPartitionless(t *testing.T) { + if _, ok := os.LookupEnv("GHW_TESTING_SKIP_BLOCK"); ok { + t.Skip("Skipping block tests.") + } + baseDir, _ := ioutil.TempDir("", "test") + defer os.RemoveAll(baseDir) + ctx := context.New() + ctx.Chroot = baseDir + paths := linuxpath.New(ctx) + + _ = os.MkdirAll(paths.SysBlock, 0755) + _ = os.MkdirAll(paths.RunUdevData, 0755) + + // Emulate a disk with no partitions + _ = os.Mkdir(filepath.Join(paths.SysBlock, "sda"), 0755) + _ = ioutil.WriteFile(filepath.Join(paths.SysBlock, "sda", "dev"), []byte("259:0\n"), 0644) + partitions := diskPartitions(ctx, paths, "sda") + if len(partitions) == 0 { + t.Fatalf("Got no partitions but expected sda") + } +} + func TestDiskPartLabel(t *testing.T) { if _, ok := os.LookupEnv("GHW_TESTING_SKIP_BLOCK"); ok { t.Skip("Skipping block tests.")