package unraid import ( "context" "net/http" "net/http/httptest" "testing" "time" "github.com/itworx/pulse/internal/pool" ) func TestPoolSourceUsesOnlyExplicitFilesystemAggregates(t *testing.T) { server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { _, _ = w.Write([]byte(`{"data":{"array":{"state":"STARTED","parities":[],"disks":[],"caches":[{"id":"cache-id","name":"cache","type":"CACHE","size":"1000","status":"DISK_OK","fsSize":"900","fsUsed":"300","fsFree":"600","fsType":"zfs"},{"id":"cache-member","name":"cache2","type":"CACHE","size":"1000","status":"DISK_OK","fsSize":null,"fsUsed":null,"fsFree":null,"fsType":null},{"id":"ssd-id","name":"ssd","type":"CACHE","size":"2000","status":"DISK_OK","fsSize":"1800","fsUsed":"1200","fsFree":"600","fsType":"zfs"}]}}}`)) })) defer server.Close() client, err := New(server.URL, "test-key", server.Client()) if err != nil { t.Fatal(err) } now := time.Date(2026, 8, 10, 10, 0, 0, 0, time.UTC) snapshot, err := (PoolSource{Client: client, Now: func() time.Time { return now }}).Snapshot(context.Background()) if err != nil { t.Fatal(err) } if len(snapshot.Pools) != 2 || snapshot.Pools[0].Name != "cache" || snapshot.Pools[1].Name != "ssd" { t.Fatalf("pools = %+v", snapshot.Pools) } if snapshot.Pools[0].UsableBytes != 900*1024 || snapshot.Pools[0].UsedBytes != 300*1024 || snapshot.Pools[0].State != pool.StateHealthy { t.Fatalf("pool aggregate = %+v", snapshot.Pools[0]) } if snapshot.Pools[0].Capabilities.Capacity != pool.CapabilityAvailable || snapshot.Pools[0].Capabilities.Members != pool.CapabilityUnsupported { t.Fatalf("capabilities = %+v", snapshot.Pools[0].Capabilities) } } func TestPoolSourceRejectsInvalidExplicitAggregate(t *testing.T) { server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { _, _ = w.Write([]byte(`{"data":{"array":{"caches":[{"id":"cache","name":"cache","status":"DISK_OK","fsSize":"100","fsUsed":"101","fsType":"zfs"}]}}}`)) })) defer server.Close() client, err := New(server.URL, "test-key", server.Client()) if err != nil { t.Fatal(err) } if _, err := (PoolSource{Client: client}).Snapshot(context.Background()); err == nil { t.Fatal("expected invalid pool usage rejection") } }