(t *testing.T)
| 226 | } |
| 227 | |
| 228 | func 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 | |
| 259 | func TestDiskTypeUdev(t *testing.T) { |
| 260 | if _, ok := os.LookupEnv("GHW_TESTING_SKIP_BLOCK"); ok { |
nothing calls this directly
no test coverage detected
searching dependent graphs…