|
|
|
@@ -10,6 +10,7 @@ import ( |
|
|
|
"testing" |
|
|
|
|
|
|
|
cfgpkg "github.com/jan/fm-rds-tx/internal/config" |
|
|
|
"github.com/jan/fm-rds-tx/internal/ingest" |
|
|
|
"github.com/jan/fm-rds-tx/internal/output" |
|
|
|
) |
|
|
|
|
|
|
|
@@ -176,6 +177,36 @@ func TestRuntimeWithoutDriver(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func TestRuntimeIncludesIngestStats(t *testing.T) { |
|
|
|
srv := NewServer(cfgpkg.Default()) |
|
|
|
srv.SetIngestRuntime(&fakeIngestRuntime{ |
|
|
|
stats: ingest.Stats{ |
|
|
|
Active: ingest.SourceDescriptor{ID: "stdin-main", Kind: "stdin-pcm"}, |
|
|
|
Runtime: ingest.RuntimeStats{State: "running"}, |
|
|
|
}, |
|
|
|
}) |
|
|
|
rec := httptest.NewRecorder() |
|
|
|
srv.Handler().ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/runtime", nil)) |
|
|
|
if rec.Code != http.StatusOK { |
|
|
|
t.Fatalf("status: %d", rec.Code) |
|
|
|
} |
|
|
|
var body map[string]any |
|
|
|
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil { |
|
|
|
t.Fatalf("unmarshal runtime: %v", err) |
|
|
|
} |
|
|
|
ingest, ok := body["ingest"].(map[string]any) |
|
|
|
if !ok { |
|
|
|
t.Fatalf("expected ingest stats, got %T", body["ingest"]) |
|
|
|
} |
|
|
|
active, ok := ingest["active"].(map[string]any) |
|
|
|
if !ok { |
|
|
|
t.Fatalf("expected ingest.active map, got %T", ingest["active"]) |
|
|
|
} |
|
|
|
if active["id"] != "stdin-main" { |
|
|
|
t.Fatalf("unexpected ingest active id: %v", active["id"]) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func TestRuntimeReportsFaultHistory(t *testing.T) { |
|
|
|
srv := NewServer(cfgpkg.Default()) |
|
|
|
history := []map[string]any{ |
|
|
|
@@ -604,12 +635,20 @@ type fakeAudioIngress struct { |
|
|
|
totalFrames int |
|
|
|
} |
|
|
|
|
|
|
|
type fakeIngestRuntime struct { |
|
|
|
stats ingest.Stats |
|
|
|
} |
|
|
|
|
|
|
|
func (f *fakeAudioIngress) WritePCM16(data []byte) (int, error) { |
|
|
|
frames := len(data) / 4 |
|
|
|
f.totalFrames += frames |
|
|
|
return frames, nil |
|
|
|
} |
|
|
|
|
|
|
|
func (f *fakeIngestRuntime) Stats() ingest.Stats { |
|
|
|
return f.stats |
|
|
|
} |
|
|
|
|
|
|
|
func (f *fakeTXController) StartTX() error { return nil } |
|
|
|
func (f *fakeTXController) StopTX() error { return nil } |
|
|
|
func (f *fakeTXController) TXStats() map[string]any { |
|
|
|
|