mirror of
https://github.com/gesellix/Bose-SoundTouch.git
synced 2026-08-18 08:36:13 +00:00
Mirrors the .md/.txt sweep across all tracked _test.go, testdata XML,
and .http integration files. Test files are self-contained (producer
+ assertion in the same file), so the matched-pair swap stays green
under `go test ./...`.
Mapping applied:
192.168.178.[0-9]+ → 192.0.2.[same]
192.168.1.[0-9]+ → 192.0.2.[same]
Sound Machinechen → Living Room SoundTouch
A Sound Machine → Kitchen SoundTouch
A81B6A536A98 + case/separator variants → AABBCCDDEEFF (etc.)
A81B6A849D99 → AABBCCDDEE01
A81B6A849D88 → AABBCCDDEE03
A81B6A536A09 → AABBCCDDEE04
884AEAEEBD27 → AABBCCDDEE02
3230304 → 1000001
9569497 → 1000002
Two semantic fixes alongside the bulk swap:
- pkg/service/zeroconf/zeroconf_test.go: the "private 192" and
"strips query" cases pin acceptance of RFC-1918 192.168/16. They
must use a real 192.168 value; doc-range IPs would (correctly) be
rejected by validateZcBaseURL. Switched to 192.168.10.10 — generic
enough not to match any home LAN default, real enough for the
validator. Added a comment explaining why this single test still
carries a 192.168 literal.
- pkg/service/setup/setup_test.go: TestTestDNSRedirection mocks the
device's `od -An -tu1` byte output, which is space-separated
octets ("192 168 1 100"). My sed only matched the dot-separated
form, so the mock was returning the old IP while the test
assertions had moved to the doc range. Updated to " 192 0 2 100".
go build ./... clean. go test ./... clean (only TestDocsConsistency
remains failing, which is a pre-existing/untracked-file issue).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
91 lines
2.4 KiB
Go
91 lines
2.4 KiB
Go
package discovery
|
|
|
|
import (
|
|
"encoding/xml"
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/gesellix/bose-soundtouch/pkg/models"
|
|
)
|
|
|
|
func TestEnrichDeviceInfo(t *testing.T) {
|
|
// Mock UPnP device description XML
|
|
xmlData := `<?xml version="1.0" encoding="utf-8"?>
|
|
<root xmlns="urn:schemas-upnp-org:device-1-0">
|
|
<device>
|
|
<friendlyName>Sound Machinery</friendlyName>
|
|
<modelName>SoundTouch 10</modelName>
|
|
<serialNumber>AABBCCDDEE04</serialNumber>
|
|
</device>
|
|
</root>`
|
|
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "text/xml")
|
|
fmt.Fprint(w, xmlData)
|
|
}))
|
|
defer server.Close()
|
|
|
|
device := &models.DiscoveredDevice{
|
|
Host: "127.0.0.1",
|
|
Name: "Initial Name",
|
|
}
|
|
|
|
service := NewService(1 * time.Second)
|
|
service.httpClient = server.Client()
|
|
err := service.EnrichDeviceInfo(device, server.URL)
|
|
|
|
if err != nil {
|
|
t.Fatalf("enrichDeviceInfo failed: %v", err)
|
|
}
|
|
|
|
if device.Name != "Sound Machinery" {
|
|
t.Errorf("expected Name 'Sound Machinery', got '%s'", device.Name)
|
|
}
|
|
|
|
if device.ModelID != "SoundTouch 10" {
|
|
t.Errorf("expected ModelID 'SoundTouch 10', got '%s'", device.ModelID)
|
|
}
|
|
|
|
if device.UPnPSerial != "AABBCCDDEE04" {
|
|
t.Errorf("expected UPnPSerial 'AABBCCDDEE04', got '%s'", device.UPnPSerial)
|
|
}
|
|
}
|
|
|
|
func TestUPnP_Unmarshal(t *testing.T) {
|
|
data := `<?xml version="1.0" encoding="utf-8"?>
|
|
<root xmlns="urn:schemas-upnp-org:device-1-0">
|
|
<device>
|
|
<friendlyName>Sound Machinery</friendlyName>
|
|
<modelName>SoundTouch 10</modelName>
|
|
<serialNumber>AABBCCDDEE04</serialNumber>
|
|
</device>
|
|
</root>`
|
|
|
|
var upnpRoot struct {
|
|
XMLName xml.Name `xml:"root"`
|
|
Device struct {
|
|
FriendlyName string `xml:"friendlyName"`
|
|
ModelName string `xml:"modelName"`
|
|
SerialNumber string `xml:"serialNumber"`
|
|
} `xml:"device"`
|
|
}
|
|
|
|
err := xml.Unmarshal([]byte(data), &upnpRoot)
|
|
if err != nil {
|
|
t.Fatalf("Unmarshal failed: %v", err)
|
|
}
|
|
|
|
if upnpRoot.Device.FriendlyName != "Sound Machinery" {
|
|
t.Errorf("expected FriendlyName 'Sound Machinery', got '%s'", upnpRoot.Device.FriendlyName)
|
|
}
|
|
if upnpRoot.Device.ModelName != "SoundTouch 10" {
|
|
t.Errorf("expected ModelName 'SoundTouch 10', got '%s'", upnpRoot.Device.ModelName)
|
|
}
|
|
if upnpRoot.Device.SerialNumber != "AABBCCDDEE04" {
|
|
t.Errorf("expected SerialNumber 'AABBCCDDEE04', got '%s'", upnpRoot.Device.SerialNumber)
|
|
}
|
|
}
|