|
|
@@ -6,6 +6,7 @@ import ( |
|
|
"errors" |
|
|
"errors" |
|
|
"net/http" |
|
|
"net/http" |
|
|
"net/http/httptest" |
|
|
"net/http/httptest" |
|
|
|
|
|
"strings" |
|
|
"testing" |
|
|
"testing" |
|
|
|
|
|
|
|
|
"github.com/jan/fm-rds-tx/internal/audio" |
|
|
"github.com/jan/fm-rds-tx/internal/audio" |
|
|
@@ -288,6 +289,20 @@ func TestRuntimeFaultResetSuccess(t *testing.T) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestRuntimeFaultResetRejectsBody(t *testing.T) { |
|
|
|
|
|
srv := NewServer(cfgpkg.Default()) |
|
|
|
|
|
srv.SetTXController(&fakeTXController{}) |
|
|
|
|
|
rec := httptest.NewRecorder() |
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, "/runtime/fault/reset", bytes.NewReader([]byte("nope"))) |
|
|
|
|
|
srv.Handler().ServeHTTP(rec, req) |
|
|
|
|
|
if rec.Code != http.StatusBadRequest { |
|
|
|
|
|
t.Fatalf("expected 400 when body present, got %d", rec.Code) |
|
|
|
|
|
} |
|
|
|
|
|
if !strings.Contains(rec.Body.String(), "request must not include a body") { |
|
|
|
|
|
t.Fatalf("unexpected response body: %q", rec.Body.String()) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func TestAudioStreamRequiresSource(t *testing.T) { |
|
|
func TestAudioStreamRequiresSource(t *testing.T) { |
|
|
srv := NewServer(cfgpkg.Default()) |
|
|
srv := NewServer(cfgpkg.Default()) |
|
|
rec := httptest.NewRecorder() |
|
|
rec := httptest.NewRecorder() |
|
|
@@ -349,6 +364,34 @@ func TestTXStartWithoutController(t *testing.T) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestTXStartRejectsBody(t *testing.T) { |
|
|
|
|
|
srv := NewServer(cfgpkg.Default()) |
|
|
|
|
|
srv.SetTXController(&fakeTXController{}) |
|
|
|
|
|
rec := httptest.NewRecorder() |
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, "/tx/start", bytes.NewReader([]byte("body"))) |
|
|
|
|
|
srv.Handler().ServeHTTP(rec, req) |
|
|
|
|
|
if rec.Code != http.StatusBadRequest { |
|
|
|
|
|
t.Fatalf("expected 400 when body present, got %d", rec.Code) |
|
|
|
|
|
} |
|
|
|
|
|
if !strings.Contains(rec.Body.String(), "request must not include a body") { |
|
|
|
|
|
t.Fatalf("unexpected response body: %q", rec.Body.String()) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestTXStopRejectsBody(t *testing.T) { |
|
|
|
|
|
srv := NewServer(cfgpkg.Default()) |
|
|
|
|
|
srv.SetTXController(&fakeTXController{}) |
|
|
|
|
|
rec := httptest.NewRecorder() |
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, "/tx/stop", bytes.NewReader([]byte("body"))) |
|
|
|
|
|
srv.Handler().ServeHTTP(rec, req) |
|
|
|
|
|
if rec.Code != http.StatusBadRequest { |
|
|
|
|
|
t.Fatalf("expected 400 when body present, got %d", rec.Code) |
|
|
|
|
|
} |
|
|
|
|
|
if !strings.Contains(rec.Body.String(), "request must not include a body") { |
|
|
|
|
|
t.Fatalf("unexpected response body: %q", rec.Body.String()) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func TestConfigPatchUpdatesSnapshot(t *testing.T) { |
|
|
func TestConfigPatchUpdatesSnapshot(t *testing.T) { |
|
|
srv := NewServer(cfgpkg.Default()) |
|
|
srv := NewServer(cfgpkg.Default()) |
|
|
srv.SetTXController(&fakeTXController{}) |
|
|
srv.SetTXController(&fakeTXController{}) |
|
|
|