Go-based FM stereo transmitter with RDS, Windows-first and cross-platform
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

62 linhas
1.4KB

  1. package app
  2. import (
  3. "testing"
  4. "github.com/jan/fm-rds-tx/internal/output"
  5. )
  6. func TestRuntimeIndicatorAndAlert(t *testing.T) {
  7. cases := []struct {
  8. name string
  9. health output.QueueHealth
  10. lateBuffers uint64
  11. wantIndicator RuntimeIndicator
  12. wantAlert string
  13. }{
  14. {
  15. name: "queue critical",
  16. health: output.QueueHealthCritical,
  17. lateBuffers: 0,
  18. wantIndicator: RuntimeIndicatorQueueCritical,
  19. wantAlert: "queue health critical",
  20. },
  21. {
  22. name: "queue low",
  23. health: output.QueueHealthLow,
  24. lateBuffers: 0,
  25. wantIndicator: RuntimeIndicatorDegraded,
  26. wantAlert: "queue health low",
  27. },
  28. {
  29. name: "late buffers",
  30. health: output.QueueHealthNormal,
  31. lateBuffers: 2,
  32. wantIndicator: RuntimeIndicatorDegraded,
  33. wantAlert: "late buffers",
  34. },
  35. {
  36. name: "normal",
  37. health: output.QueueHealthNormal,
  38. lateBuffers: 0,
  39. wantIndicator: RuntimeIndicatorNormal,
  40. wantAlert: "",
  41. },
  42. }
  43. for _, tc := range cases {
  44. tc := tc
  45. t.Run(tc.name, func(t *testing.T) {
  46. t.Parallel()
  47. got := runtimeIndicator(tc.health, tc.lateBuffers)
  48. if got != tc.wantIndicator {
  49. t.Fatalf("indicator: expected %s, got %s", tc.wantIndicator, got)
  50. }
  51. alert := runtimeAlert(tc.health, tc.lateBuffers)
  52. if alert != tc.wantAlert {
  53. t.Fatalf("alert: expected %q, got %q", tc.wantAlert, alert)
  54. }
  55. })
  56. }
  57. }