MCPcopy
hub / github.com/jaypipes/ghw / TestDiskPartUUID

Function TestDiskPartUUID

pkg/block/block_linux_test.go:290–318  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

288}
289
290func TestDiskPartUUID(t *testing.T) {
291 if _, ok := os.LookupEnv("GHW_TESTING_SKIP_BLOCK"); ok {
292 t.Skip("Skipping block tests.")
293 }
294 baseDir, _ := os.MkdirTemp("", "test")
295 ctx := context.TODO()
296 ctx = config.WithChroot(baseDir)(ctx)
297 paths := linuxpath.New(ctx)
298 partUUID := "11111111-1111-1111-1111-111111111111"
299
300 _ = os.MkdirAll(paths.SysBlock, 0755)
301 _ = os.MkdirAll(paths.RunUdevData, 0755)
302
303 // Emulate a disk with one partition with uuid
304 _ = os.Mkdir(filepath.Join(paths.SysBlock, "sda"), 0755)
305 _ = os.Mkdir(filepath.Join(paths.SysBlock, "sda", "sda1"), 0755)
306 _ = os.WriteFile(filepath.Join(paths.SysBlock, "sda", "sda1", "dev"), []byte("259:0\n"), 0644)
307 _ = os.WriteFile(filepath.Join(paths.RunUdevData, "b259:0"), []byte(fmt.Sprintf("E:ID_PART_ENTRY_UUID=%s\n", partUUID)), 0644)
308 uuid := diskPartUUID(paths, "sda", "sda1")
309 if uuid != partUUID {
310 t.Fatalf("Got uuid %s but expected %s", uuid, partUUID)
311 }
312
313 // Check empty uuid if not found
314 uuid = diskPartUUID(paths, "sda", "sda2")
315 if uuid != util.UNKNOWN {
316 t.Fatalf("Got uuid %s, but expected %s label", uuid, util.UNKNOWN)
317 }
318}
319
320// TestLoopDevicesWithOption tests to see if we find loop devices when the config is activated
321func TestLoopDevicesWithOption(t *testing.T) {

Callers

nothing calls this directly

Calls 3

WithChrootFunction · 0.92
NewFunction · 0.92
diskPartUUIDFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…