Skip to content

Commit

Permalink
Update unexported api calls for new functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
taigrr committed May 27, 2022
1 parent 0e160d1 commit 0a37e8a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/block/block_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 24 additions & 0 deletions pkg/block/block_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"reflect"
"testing"

"github.com/jaypipes/ghw/pkg/util"

"github.com/jaypipes/ghw/pkg/context"
"github.com/jaypipes/ghw/pkg/linuxpath"
"github.com/jaypipes/ghw/pkg/option"
Expand Down Expand Up @@ -195,6 +197,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.")
Expand Down

0 comments on commit 0a37e8a

Please sign in to comment.