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

Function TestDiskFSLabel

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

Source from the content-addressed store, hash-verified

226}
227
228func TestDiskFSLabel(t *testing.T) {
229 if _, ok := os.LookupEnv("GHW_TESTING_SKIP_BLOCK"); ok {
230 t.Skip("Skipping block tests.")
231 }
232 baseDir, _ := os.MkdirTemp("", "test")
233 defer os.RemoveAll(baseDir)
234 ctx := context.TODO()
235 ctx = config.WithChroot(baseDir)(ctx)
236 paths := linuxpath.New(ctx)
237 fsLabel := "TEST_LABEL_GHW"
238
239 _ = os.MkdirAll(paths.SysBlock, 0755)
240 _ = os.MkdirAll(paths.RunUdevData, 0755)
241
242 // Emulate a disk with one partition with label TEST_LABEL_GHW
243 _ = os.Mkdir(filepath.Join(paths.SysBlock, "sda"), 0755)
244 _ = os.Mkdir(filepath.Join(paths.SysBlock, "sda", "sda1"), 0755)
245 _ = os.WriteFile(filepath.Join(paths.SysBlock, "sda", "sda1", "dev"), []byte("259:0\n"), 0644)
246 _ = os.WriteFile(filepath.Join(paths.RunUdevData, "b259:0"), []byte(fmt.Sprintf("E:ID_FS_LABEL=%s\n", fsLabel)), 0644)
247 label := diskFSLabel(paths, "sda", "sda1")
248 if label != fsLabel {
249 t.Fatalf("Got label %s but expected %s", label, fsLabel)
250 }
251
252 // Check empty label if not found
253 label = diskFSLabel(paths, "sda", "sda2")
254 if label != util.UNKNOWN {
255 t.Fatalf("Got label %s, but expected %s label", label, util.UNKNOWN)
256 }
257}
258
259func TestDiskTypeUdev(t *testing.T) {
260 if _, ok := os.LookupEnv("GHW_TESTING_SKIP_BLOCK"); ok {

Callers

nothing calls this directly

Calls 3

WithChrootFunction · 0.92
NewFunction · 0.92
diskFSLabelFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…