mirror of
https://github.com/henrygd/beszel.git
synced 2026-10-21 22:02:34 +00:00
A refquota on a pool's root dataset caps its avail by the root's own referenced data, so used+avail can understate pool capacity when child datasets hold most of the data and trigger false disk usage alerts. Fetch refquota with the root datasets and fall back to the raw zpool figures for those pools.
38 lines
993 B
Go
38 lines
993 B
Go
//go:build testing && !linux
|
|
|
|
package zfs
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCollectorsUseUtilitiesOnNonLinux(t *testing.T) {
|
|
oldCommandOutput := commandOutput
|
|
commandOutput = func(name string, args ...string) ([]byte, error) {
|
|
switch name {
|
|
case "zpool":
|
|
return []byte("tank\t100\t50\t50\tONLINE\n"), nil
|
|
case "zfs":
|
|
if slices.Contains(args, "-d") {
|
|
return []byte("tank\t40\t60\tnone\n"), nil
|
|
}
|
|
return []byte("tank\t50\t50\t/tank\n"), nil
|
|
default:
|
|
t.Fatalf("unexpected command %s", name)
|
|
return nil, nil
|
|
}
|
|
}
|
|
t.Cleanup(func() { commandOutput = oldCommandOutput })
|
|
|
|
pools, err := PoolStats()
|
|
require.NoError(t, err)
|
|
assert.Equal(t, []PoolStat{{Name: "tank", Size: 100, Alloc: 40, Free: 60, Health: "ONLINE"}}, pools)
|
|
datasets, err := Datasets()
|
|
require.NoError(t, err)
|
|
assert.Equal(t, []Dataset{{Name: "tank", Used: 50, Avail: 50, Mountpoint: "/tank"}}, datasets)
|
|
}
|