Files
pipelines/cmd/pipelines-server/mdns_test.go
T
alan 0e16e6c9fe Republish mDNS on address change; build the APK natively when the host can
The server compares its LAN and tailnet addresses every 30 seconds and
republishes the advert when they change, so a machine that moves networks
stops advertising the address it had at startup.

./install --apk builds on this machine with the host Flutter and Android SDK
when both exist (--docker forces the container build), signing with the same
shared debug keystore so phones keep accepting updates.
2026-11-09 12:38:51 +00:00

50 lines
1.6 KiB
Go

package main
import (
"net"
"testing"
)
func TestMDNSEnvironmentSwitches(t *testing.T) {
for value, want := range map[string]bool{"": true, "1": true, "on": true, "off": false, "0": false, "FALSE": false, " disabled ": false} {
if got := envEnabled(value); got != want {
t.Errorf("envEnabled(%q) = %v, want %v", value, got, want)
}
}
for value, want := range map[string]int{"": 0, "8083": 8083, "x": 0, "70000": 0} {
if got := envPort(value); got != want {
t.Errorf("envPort(%q) = %d, want %d", value, got, want)
}
}
}
// A loopback-only server with no proxy port publishes nothing and does not
// fail: the caller only defers a non-nil stop.
func TestAdvertiseSkipsLoopbackWithoutFailing(t *testing.T) {
if stop := advertise("127.0.0.1:0", 0); stop != nil {
stop()
t.Fatal("loopback-only server was advertised")
}
}
func TestSameAddressesIgnoresOrder(t *testing.T) {
a := []net.IP{net.ParseIP("10.0.0.75"), net.ParseIP("192.168.104.82")}
b := []net.IP{net.ParseIP("192.168.104.82"), net.ParseIP("10.0.0.75")}
if !sameAddresses(a, b) {
t.Fatal("same addresses in another order compared unequal")
}
if sameAddresses(a, b[:1]) || sameAddresses(nil, b) || sameAddresses(a, []net.IP{net.ParseIP("10.0.0.75"), net.ParseIP("10.0.0.76")}) {
t.Fatal("different address sets compared equal")
}
if !sameAddresses(nil, nil) {
t.Fatal("two empty sets must compare equal")
}
}
// keepAdvertising on a loopback-only server publishes nothing, keeps its
// watcher running and stops cleanly.
func TestKeepAdvertisingStopsCleanly(t *testing.T) {
stop := keepAdvertising("127.0.0.1:0", 0)
stop()
}