Skip to content

Commit

Permalink
Adds unit test for partitionless disk
Browse files Browse the repository at this point in the history
Signed-off-by: Tai Groot <[email protected]>
  • Loading branch information
taigrr committed Mar 19, 2022
1 parent 83ef73f commit 507510d
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion pkg/block/block_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ package block

import (
"fmt"
"github.com/jaypipes/ghw/pkg/util"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"testing"

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

"github.com/jaypipes/ghw/pkg/context"
"github.com/jaypipes/ghw/pkg/linuxpath"
)
Expand Down Expand Up @@ -221,6 +222,28 @@ func TestISCSI(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 507510d

Please sign in to comment.