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ů.

118 řádky
2.8KB

  1. package factory
  2. import (
  3. "bytes"
  4. "testing"
  5. "github.com/jan/fm-rds-tx/internal/config"
  6. )
  7. func TestBuildSourceNone(t *testing.T) {
  8. cfg := config.Default()
  9. cfg.Ingest.Kind = "none"
  10. src, ingress, err := BuildSource(cfg, Deps{})
  11. if err != nil {
  12. t.Fatalf("build source: %v", err)
  13. }
  14. if src != nil || ingress != nil {
  15. t.Fatalf("expected nil source and ingress for kind=none")
  16. }
  17. }
  18. func TestBuildSourceHTTPRawProvidesIngress(t *testing.T) {
  19. cfg := config.Default()
  20. cfg.Ingest.Kind = "http-raw"
  21. src, ingress, err := BuildSource(cfg, Deps{})
  22. if err != nil {
  23. t.Fatalf("build source: %v", err)
  24. }
  25. if src == nil {
  26. t.Fatalf("expected source")
  27. }
  28. if ingress == nil {
  29. t.Fatalf("expected ingress for http-raw")
  30. }
  31. }
  32. func TestBuildSourceKindIsNormalized(t *testing.T) {
  33. cfg := config.Default()
  34. cfg.Ingest.Kind = " HTTP-RAW "
  35. src, ingress, err := BuildSource(cfg, Deps{})
  36. if err != nil {
  37. t.Fatalf("build source: %v", err)
  38. }
  39. if src == nil || ingress == nil {
  40. t.Fatalf("expected source and ingress for normalized http-raw kind")
  41. }
  42. if got := src.Descriptor().Kind; got != "http-raw" {
  43. t.Fatalf("source kind=%q want http-raw", got)
  44. }
  45. }
  46. func TestBuildSourceStdin(t *testing.T) {
  47. cfg := config.Default()
  48. cfg.Ingest.Kind = "stdin"
  49. src, ingress, err := BuildSource(cfg, Deps{Stdin: bytes.NewReader(nil)})
  50. if err != nil {
  51. t.Fatalf("build source: %v", err)
  52. }
  53. if src == nil {
  54. t.Fatalf("expected source")
  55. }
  56. if ingress != nil {
  57. t.Fatalf("expected no ingress for stdin")
  58. }
  59. if got := src.Descriptor().Kind; got != "stdin-pcm" {
  60. t.Fatalf("source kind=%s", got)
  61. }
  62. }
  63. func TestBuildSourceIcecastUsesDecoderPreference(t *testing.T) {
  64. cfg := config.Default()
  65. cfg.Ingest.Kind = "icecast"
  66. cfg.Ingest.Icecast.URL = "http://localhost:8000/stream"
  67. cfg.Ingest.Icecast.Decoder = "ffmpeg"
  68. src, ingress, err := BuildSource(cfg, Deps{})
  69. if err != nil {
  70. t.Fatalf("build source: %v", err)
  71. }
  72. if src == nil {
  73. t.Fatalf("expected source")
  74. }
  75. if ingress != nil {
  76. t.Fatalf("expected no ingress for icecast")
  77. }
  78. if got := src.Descriptor().Codec; got != "ffmpeg" {
  79. t.Fatalf("codec=%s want ffmpeg", got)
  80. }
  81. }
  82. func TestBuildSourceUnsupportedKind(t *testing.T) {
  83. cfg := config.Default()
  84. cfg.Ingest.Kind = "nope"
  85. _, _, err := BuildSource(cfg, Deps{})
  86. if err == nil {
  87. t.Fatalf("expected error")
  88. }
  89. }
  90. func TestSampleRateForKind(t *testing.T) {
  91. cfg := config.Default()
  92. cfg.Ingest.Kind = "stdin"
  93. cfg.Ingest.Stdin.SampleRateHz = 48000
  94. if got := SampleRateForKind(cfg); got != 48000 {
  95. t.Fatalf("stdin sample rate=%d", got)
  96. }
  97. cfg.Ingest.Kind = "http-raw"
  98. cfg.Ingest.HTTPRaw.SampleRateHz = 32000
  99. if got := SampleRateForKind(cfg); got != 32000 {
  100. t.Fatalf("http-raw sample rate=%d", got)
  101. }
  102. cfg.Ingest.Kind = "icecast"
  103. if got := SampleRateForKind(cfg); got != 44100 {
  104. t.Fatalf("icecast sample rate=%d", got)
  105. }
  106. }