Skip to content

Commit d6bb4e6

Browse files
antopltantoplt
authored andcommitted
Add disk integration file test
1 parent a86ba0d commit d6bb4e6

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

test/integration/disk_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package integration
2+
3+
import (
4+
"testing"
5+
6+
"github.com/bluewave-labs/capture/internal/metric"
7+
)
8+
9+
// TestDiskMetricsContent verifies that disk metrics can be collected and contain valid data.
10+
// It specifically checks that the Mountpoint field is correctly populated for detected disks.
11+
func TestDiskMetricsContent(t *testing.T) {
12+
// Attempt to collect disk metrics using the internal metric package
13+
metricsSlice, errs := metric.CollectDiskMetrics()
14+
15+
// Log any partial errors encountered during collection (e.g. permission denied on specific partitions)
16+
// We do not fail the test here as partial failures are expected in some environments.
17+
if len(errs) > 0 {
18+
t.Logf("Encountered partial errors collecting disk metrics: %v", errs)
19+
}
20+
21+
// Verify that we retrieved at least some metrics
22+
if len(metricsSlice) == 0 {
23+
t.Log("No disk metrics found. Skipping validation.")
24+
return
25+
}
26+
27+
foundValidDisk := false
28+
29+
for _, m := range metricsSlice {
30+
// Assert that the metric is of type *DiskData
31+
diskData, ok := m.(*metric.DiskData)
32+
if !ok {
33+
t.Errorf("Expected *metric.DiskData, got %T", m)
34+
continue
35+
}
36+
37+
// Log the discovered device and mountpoint for debugging context
38+
t.Logf("Found Disk: Device=%s, Mountpoint=%s", diskData.Device, diskData.Mountpoint)
39+
40+
// Validation: The Mountpoint field must not be empty
41+
if diskData.Mountpoint == "" {
42+
t.Errorf("Disk device %s has an empty Mountpoint field", diskData.Device)
43+
} else {
44+
foundValidDisk = true
45+
}
46+
}
47+
48+
// If we iterated through metrics but didn't find any valid disk with a mountpoint, log a warning.
49+
if !foundValidDisk {
50+
t.Log("WARNING: No valid disks with mountpoints were verified")
51+
}
52+
}

0 commit comments

Comments
 (0)