Go-based FM stereo transmitter with RDS, Windows-first and cross-platform
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.9KB

  1. package main
  2. import (
  3. "testing"
  4. apppkg "github.com/jan/fm-rds-tx/internal/app"
  5. cfgpkg "github.com/jan/fm-rds-tx/internal/config"
  6. "github.com/jan/fm-rds-tx/internal/output"
  7. "github.com/jan/fm-rds-tx/internal/platform"
  8. )
  9. func TestTxBridgeExportsQueueStats(t *testing.T) {
  10. cfg := cfgpkg.Default()
  11. driver := platform.NewSimulatedDriver(nil)
  12. engine := apppkg.NewEngine(cfg, driver)
  13. bridge := &txBridge{engine: engine}
  14. stats := bridge.TXStats()
  15. raw, ok := stats["queue"]
  16. if !ok {
  17. t.Fatalf("expected queue stats in tx stats")
  18. }
  19. queue, ok := raw.(output.QueueStats)
  20. if !ok {
  21. t.Fatalf("queue stats type mismatch: %T", raw)
  22. }
  23. if queue.Capacity != cfg.Runtime.FrameQueueCapacity {
  24. t.Fatalf("unexpected queue capacity: want %d got %d", cfg.Runtime.FrameQueueCapacity, queue.Capacity)
  25. }
  26. if queue.Health != output.QueueHealthCritical {
  27. t.Fatalf("queue health should be critical with empty queue, got %s", queue.Health)
  28. }
  29. indicatorRaw, ok := stats["runtimeIndicator"]
  30. if !ok {
  31. t.Fatalf("expected runtimeIndicator in tx stats")
  32. }
  33. indicator, ok := indicatorRaw.(apppkg.RuntimeIndicator)
  34. if !ok {
  35. t.Fatalf("runtimeIndicator type mismatch: %T", indicatorRaw)
  36. }
  37. if indicator != apppkg.RuntimeIndicatorQueueCritical {
  38. t.Fatalf("runtime indicator should be queueCritical, got %s", indicator)
  39. }
  40. freqRaw, ok := stats["appliedFrequencyMHz"]
  41. if !ok {
  42. t.Fatalf("missing appliedFrequencyMHz")
  43. }
  44. freq, ok := freqRaw.(float64)
  45. if !ok {
  46. t.Fatalf("appliedFrequencyMHz type mismatch: %T", freqRaw)
  47. }
  48. if freq != cfg.FM.FrequencyMHz {
  49. t.Fatalf("applied frequency mismatch: want %v got %v", cfg.FM.FrequencyMHz, freq)
  50. }
  51. if historyRaw, ok := stats["faultHistory"]; !ok {
  52. t.Fatalf("expected faultHistory in tx stats")
  53. } else if history, ok := historyRaw.([]apppkg.FaultEvent); !ok {
  54. t.Fatalf("faultHistory type mismatch: %T", historyRaw)
  55. } else if len(history) != 0 {
  56. t.Fatalf("expected no faults yet, got %d", len(history))
  57. }
  58. }