mirror of
https://github.com/gesellix/Bose-SoundTouch.git
synced 2026-08-18 08:36:13 +00:00
Fix bmx base url
This commit is contained in:
@@ -4,7 +4,6 @@ package handlers
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/gesellix/bose-soundtouch/pkg/service/bmx"
|
||||
@@ -13,10 +12,7 @@ import (
|
||||
|
||||
// HandleBMXRegistry returns the BMX service registry.
|
||||
func (s *Server) HandleBMXRegistry(w http.ResponseWriter, _ *http.Request) {
|
||||
baseURL := os.Getenv("BASE_URL")
|
||||
if baseURL == "" {
|
||||
baseURL = "http://localhost:8000"
|
||||
}
|
||||
baseURL := s.serverURL
|
||||
|
||||
content := string(bmxServicesJSON)
|
||||
content = strings.ReplaceAll(content, "{BMX_SERVER}", baseURL)
|
||||
|
||||
@@ -39,6 +39,10 @@ func TestBMXServices(t *testing.T) {
|
||||
|
||||
// Verify placeholder replacement
|
||||
bodyStr := string(body)
|
||||
if !strings.Contains(bodyStr, "http://localhost:8001") {
|
||||
t.Errorf("Response does not contain expected baseURL http://localhost:8001, got: %s", bodyStr)
|
||||
}
|
||||
|
||||
if strings.Contains(bodyStr, "{BMX_SERVER}") {
|
||||
t.Error("Response still contains {BMX_SERVER} placeholder")
|
||||
}
|
||||
@@ -48,6 +52,31 @@ func TestBMXServices(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBMXServices_EmptyBaseURL(t *testing.T) {
|
||||
r, _ := setupRouter("", nil)
|
||||
|
||||
ts := httptest.NewServer(r)
|
||||
defer ts.Close()
|
||||
|
||||
res, err := http.Get(ts.URL + "/bmx/registry/v1/services")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() { _ = res.Body.Close() }()
|
||||
|
||||
body, _ := io.ReadAll(res.Body)
|
||||
bodyStr := string(body)
|
||||
|
||||
// Since we removed the fallback, it should use the empty baseURL
|
||||
if strings.Contains(bodyStr, "http://localhost:8000") {
|
||||
t.Error("Response contains fallback URL http://localhost:8000, which should be removed")
|
||||
}
|
||||
|
||||
if strings.Contains(bodyStr, "{BMX_SERVER}") {
|
||||
t.Error("Response still contains {BMX_SERVER} placeholder")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOrionPlayback(t *testing.T) {
|
||||
r, _ := setupRouter("http://localhost:8001", nil)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
func setupRouter(targetURL string, ds *datastore.DataStore) (*chi.Mux, *Server) {
|
||||
server := NewServer(ds, nil, "http://localhost:8000", false, false, false, false, false, false)
|
||||
server := NewServer(ds, nil, targetURL, false, false, false, false, false, false)
|
||||
server.SetSoundcorkURL(targetURL)
|
||||
|
||||
r := chi.NewRouter()
|
||||
|
||||
Reference in New Issue
Block a user