Go-based FM stereo transmitter with RDS, Windows-first and cross-platform
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

89 satır
2.5KB

  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 TestIngestEnabled(t *testing.T) {
  10. tests := []struct {
  11. name string
  12. kind string
  13. want bool
  14. }{
  15. {name: "empty", kind: "", want: false},
  16. {name: "none", kind: "none", want: false},
  17. {name: "none uppercase and spaces", kind: " NONE ", want: false},
  18. {name: "stdin", kind: "stdin", want: true},
  19. {name: "http raw uppercase", kind: " HTTP-RAW ", want: true},
  20. }
  21. for _, tc := range tests {
  22. t.Run(tc.name, func(t *testing.T) {
  23. if got := ingestEnabled(tc.kind); got != tc.want {
  24. t.Fatalf("ingestEnabled(%q)=%v want %v", tc.kind, got, tc.want)
  25. }
  26. })
  27. }
  28. }
  29. func TestTxBridgeExportsQueueStats(t *testing.T) {
  30. cfg := cfgpkg.Default()
  31. driver := platform.NewSimulatedDriver(nil)
  32. engine := apppkg.NewEngine(cfg, driver)
  33. bridge := &txBridge{engine: engine}
  34. stats := bridge.TXStats()
  35. raw, ok := stats["queue"]
  36. if !ok {
  37. t.Fatalf("expected queue stats in tx stats")
  38. }
  39. queue, ok := raw.(output.QueueStats)
  40. if !ok {
  41. t.Fatalf("queue stats type mismatch: %T", raw)
  42. }
  43. if queue.Capacity != cfg.Runtime.FrameQueueCapacity {
  44. t.Fatalf("unexpected queue capacity: want %d got %d", cfg.Runtime.FrameQueueCapacity, queue.Capacity)
  45. }
  46. if queue.Health != output.QueueHealthCritical {
  47. t.Fatalf("queue health should be critical with empty queue, got %s", queue.Health)
  48. }
  49. indicatorRaw, ok := stats["runtimeIndicator"]
  50. if !ok {
  51. t.Fatalf("expected runtimeIndicator in tx stats")
  52. }
  53. indicator, ok := indicatorRaw.(apppkg.RuntimeIndicator)
  54. if !ok {
  55. t.Fatalf("runtimeIndicator type mismatch: %T", indicatorRaw)
  56. }
  57. if indicator != apppkg.RuntimeIndicatorQueueCritical {
  58. t.Fatalf("runtime indicator should be queueCritical, got %s", indicator)
  59. }
  60. freqRaw, ok := stats["appliedFrequencyMHz"]
  61. if !ok {
  62. t.Fatalf("missing appliedFrequencyMHz")
  63. }
  64. freq, ok := freqRaw.(float64)
  65. if !ok {
  66. t.Fatalf("appliedFrequencyMHz type mismatch: %T", freqRaw)
  67. }
  68. if freq != cfg.FM.FrequencyMHz {
  69. t.Fatalf("applied frequency mismatch: want %v got %v", cfg.FM.FrequencyMHz, freq)
  70. }
  71. if historyRaw, ok := stats["faultHistory"]; !ok {
  72. t.Fatalf("expected faultHistory in tx stats")
  73. } else if history, ok := historyRaw.([]apppkg.FaultEvent); !ok {
  74. t.Fatalf("faultHistory type mismatch: %T", historyRaw)
  75. } else if len(history) != 0 {
  76. t.Fatalf("expected no faults yet, got %d", len(history))
  77. }
  78. }