mirror of
https://github.com/gesellix/Bose-SoundTouch.git
synced 2026-08-14 22:56:14 +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>
80 lines
2.6 KiB
Go
80 lines
2.6 KiB
Go
package datastore
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/gesellix/bose-soundtouch/pkg/service/constants"
|
|
)
|
|
|
|
func TestDataStore_MacAddressMapping(t *testing.T) {
|
|
if err := os.MkdirAll("testdata/mapping", 0755); err != nil {
|
|
t.Fatalf("failed to create temp dir: %v", err)
|
|
}
|
|
defer os.RemoveAll("testdata/mapping")
|
|
|
|
accountID := "12345"
|
|
serialNumber := "SERIAL123"
|
|
macAddress := "AABBCCDDEEFF"
|
|
|
|
// Create directory structure
|
|
deviceDir := filepath.Join("testdata/mapping", "accounts", accountID, "devices", serialNumber)
|
|
if err := os.MkdirAll(deviceDir, 0755); err != nil {
|
|
t.Fatalf("failed to create device dir: %v", err)
|
|
}
|
|
|
|
// Create DeviceInfo.xml with MAC address
|
|
deviceInfoXML := `<?xml version="1.0" encoding="UTF-8"?>
|
|
<info deviceID="` + serialNumber + `">
|
|
<name>Test Device</name>
|
|
<components>
|
|
<component>
|
|
<componentCategory>SCM</componentCategory>
|
|
<softwareVersion>1.0</softwareVersion>
|
|
<serialNumber>` + serialNumber + `</serialNumber>
|
|
</component>
|
|
</components>
|
|
<networkInfo type="SCM">
|
|
<macAddress>` + macAddress + `</macAddress>
|
|
<ipAddress>192.0.2.10</ipAddress>
|
|
</networkInfo>
|
|
</info>`
|
|
if err := os.WriteFile(filepath.Join(deviceDir, constants.DeviceInfoFile), []byte(deviceInfoXML), 0644); err != nil {
|
|
t.Fatalf("failed to write DeviceInfo.xml: %v", err)
|
|
}
|
|
|
|
// Create Presets.xml so we can verify access
|
|
presetsXML := `<presets><preset id="1">test</preset></presets>`
|
|
if err := os.WriteFile(filepath.Join(deviceDir, constants.PresetsFile), []byte(presetsXML), 0644); err != nil {
|
|
t.Fatalf("failed to write Presets.xml: %v", err)
|
|
}
|
|
|
|
ds := NewDataStore("testdata/mapping")
|
|
if err := ds.Initialize(); err != nil {
|
|
t.Fatalf("failed to initialize datastore: %v", err)
|
|
}
|
|
|
|
// Test mapping resolution in AccountDeviceDir
|
|
resolvedDir := ds.AccountDeviceDir(accountID, macAddress)
|
|
expectedDir, _ := filepath.Abs(filepath.Join("testdata/mapping", "accounts", accountID, "devices", serialNumber))
|
|
if resolvedDir != expectedDir {
|
|
t.Errorf("expected dir %s, got %s", expectedDir, resolvedDir)
|
|
}
|
|
|
|
// Test that we can still use the serial number directly
|
|
resolvedDirSerial := ds.AccountDeviceDir(accountID, serialNumber)
|
|
if resolvedDirSerial != expectedDir {
|
|
t.Errorf("expected dir %s when using serial, got %s", expectedDir, resolvedDirSerial)
|
|
}
|
|
|
|
// Test GetPresets using MAC address
|
|
presets, err := ds.GetPresets(accountID, macAddress)
|
|
if err != nil {
|
|
t.Errorf("GetPresets failed with MAC address: %v", err)
|
|
}
|
|
if len(presets) == 0 {
|
|
t.Error("expected presets to be loaded")
|
|
}
|
|
}
|