View Javadoc
1   /*
2    * Copyright 2022 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.driver.unix.openbsd.disk;
6   
7   import static org.hamcrest.MatcherAssert.assertThat;
8   import static org.hamcrest.Matchers.greaterThanOrEqualTo;
9   import static org.hamcrest.Matchers.not;
10  import static org.hamcrest.Matchers.nullValue;
11  import static org.junit.jupiter.api.Assertions.assertTrue;
12  
13  import java.util.List;
14  
15  import org.junit.jupiter.api.Test;
16  import org.junit.jupiter.api.condition.EnabledOnOs;
17  import org.junit.jupiter.api.condition.OS;
18  
19  import oshi.hardware.HWPartition;
20  import oshi.software.os.unix.openbsd.OpenBsdOperatingSystem;
21  import oshi.util.platform.unix.openbsd.OpenBsdSysctlUtil;
22  import oshi.util.tuples.Quartet;
23  
24  @EnabledOnOs(OS.OPENBSD)
25  class DisklabelTest {
26      @Test
27      void testDisklabel() {
28          String[] devices = OpenBsdSysctlUtil.sysctl("hw.disknames", "").split(",");
29          for (String device : devices) {
30              String diskName = device.split(":")[0];
31              Quartet<String, String, Long, List<HWPartition>> diskdata = Disklabel.getDiskParams(diskName);
32              // First 3 only available with elevation
33              if (new OpenBsdOperatingSystem().isElevated()) {
34                  assertThat("Disk label is not null", diskdata.getA(), not(nullValue()));
35                  assertThat("Disk duid is not null", diskdata.getB(), not(nullValue()));
36                  assertThat("Disk size is nonnegative", diskdata.getC().longValue(), greaterThanOrEqualTo(0L));
37                  for (HWPartition part : diskdata.getD()) {
38                      assertTrue(part.getIdentification().startsWith(diskName), "Partition ID starts with disk");
39                  }
40              }
41          }
42      }
43  }