Go-based FM stereo transmitter with RDS, Windows-first and cross-platform
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

103 行
2.4KB

  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 TestBuildSourceStdin(t *testing.T) {
  33. cfg := config.Default()
  34. cfg.Ingest.Kind = "stdin"
  35. src, ingress, err := BuildSource(cfg, Deps{Stdin: bytes.NewReader(nil)})
  36. if err != nil {
  37. t.Fatalf("build source: %v", err)
  38. }
  39. if src == nil {
  40. t.Fatalf("expected source")
  41. }
  42. if ingress != nil {
  43. t.Fatalf("expected no ingress for stdin")
  44. }
  45. if got := src.Descriptor().Kind; got != "stdin-pcm" {
  46. t.Fatalf("source kind=%s", got)
  47. }
  48. }
  49. func TestBuildSourceIcecastUsesDecoderPreference(t *testing.T) {
  50. cfg := config.Default()
  51. cfg.Ingest.Kind = "icecast"
  52. cfg.Ingest.Icecast.URL = "http://localhost:8000/stream"
  53. cfg.Ingest.Icecast.Decoder = "ffmpeg"
  54. src, ingress, err := BuildSource(cfg, Deps{})
  55. if err != nil {
  56. t.Fatalf("build source: %v", err)
  57. }
  58. if src == nil {
  59. t.Fatalf("expected source")
  60. }
  61. if ingress != nil {
  62. t.Fatalf("expected no ingress for icecast")
  63. }
  64. if got := src.Descriptor().Codec; got != "ffmpeg" {
  65. t.Fatalf("codec=%s want ffmpeg", got)
  66. }
  67. }
  68. func TestBuildSourceUnsupportedKind(t *testing.T) {
  69. cfg := config.Default()
  70. cfg.Ingest.Kind = "nope"
  71. _, _, err := BuildSource(cfg, Deps{})
  72. if err == nil {
  73. t.Fatalf("expected error")
  74. }
  75. }
  76. func TestSampleRateForKind(t *testing.T) {
  77. cfg := config.Default()
  78. cfg.Ingest.Kind = "stdin"
  79. cfg.Ingest.Stdin.SampleRateHz = 48000
  80. if got := SampleRateForKind(cfg); got != 48000 {
  81. t.Fatalf("stdin sample rate=%d", got)
  82. }
  83. cfg.Ingest.Kind = "http-raw"
  84. cfg.Ingest.HTTPRaw.SampleRateHz = 32000
  85. if got := SampleRateForKind(cfg); got != 32000 {
  86. t.Fatalf("http-raw sample rate=%d", got)
  87. }
  88. cfg.Ingest.Kind = "icecast"
  89. if got := SampleRateForKind(cfg); got != 44100 {
  90. t.Fatalf("icecast sample rate=%d", got)
  91. }
  92. }