Go-based FM stereo transmitter with RDS, Windows-first and cross-platform
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

73 řádky
2.0KB

  1. package app
  2. import (
  3. "testing"
  4. cfgpkg "github.com/jan/fm-rds-tx/internal/config"
  5. "github.com/jan/fm-rds-tx/internal/output"
  6. "github.com/jan/fm-rds-tx/internal/platform"
  7. )
  8. func TestFaultSeverityString(t *testing.T) {
  9. cases := []struct {
  10. severity FaultSeverity
  11. want string
  12. }{
  13. {FaultSeverityWarn, "warn"},
  14. {FaultSeverityDegraded, "degraded"},
  15. {FaultSeverityMuted, "muted"},
  16. {FaultSeverityFaulted, "faulted"},
  17. {FaultSeverity(99), "unknown"},
  18. }
  19. for _, tc := range cases {
  20. t.Run(tc.want, func(t *testing.T) {
  21. if got := tc.severity.String(); got != tc.want {
  22. t.Fatalf("expected %s, got %s", tc.want, got)
  23. }
  24. if txt, _ := tc.severity.MarshalText(); string(txt) != tc.want {
  25. t.Fatalf("MarshalText mismatch: want %s, got %s", tc.want, txt)
  26. }
  27. })
  28. }
  29. }
  30. func TestEngineRecordsQueueCriticalFault(t *testing.T) {
  31. e := NewEngine(cfgpkg.Default(), platform.NewSimulatedDriver(nil))
  32. e.setRuntimeState(RuntimeStateRunning)
  33. queue := output.QueueStats{Depth: 3, Health: output.QueueHealthCritical}
  34. for i := 0; i < queueCriticalStreakThreshold; i++ {
  35. e.evaluateRuntimeState(queue, false)
  36. }
  37. last := e.LastFault()
  38. if last == nil {
  39. t.Fatal("expected fault recorded, got nil")
  40. }
  41. if last.Reason != FaultReasonQueueCritical {
  42. t.Fatalf("expected queue critical reason, got %s", last.Reason)
  43. }
  44. if last.Severity != FaultSeverityDegraded {
  45. t.Fatalf("expected degraded severity, got %s", last.Severity)
  46. }
  47. }
  48. func TestEngineRecordsLateBufferFault(t *testing.T) {
  49. e := NewEngine(cfgpkg.Default(), platform.NewSimulatedDriver(nil))
  50. e.setRuntimeState(RuntimeStateRunning)
  51. queue := output.QueueStats{Depth: 5, Health: output.QueueHealthNormal}
  52. e.evaluateRuntimeState(queue, true)
  53. last := e.LastFault()
  54. if last == nil {
  55. t.Fatal("expected fault recorded for late buffers")
  56. }
  57. if last.Reason != FaultReasonLateBuffers {
  58. t.Fatalf("expected late buffer reason, got %s", last.Reason)
  59. }
  60. if last.Severity != FaultSeverityWarn {
  61. t.Fatalf("expected warn severity, got %s", last.Severity)
  62. }
  63. }