mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-14 15:07:55 +00:00
net/interfaces: define DefaultRouteInterface and State.DefaultRouteInterface
It was pretty ill-defined before and mostly for logging. But I wanted to start depending on it, so define what it is and make Windows match the other operating systems, without losing the log output we had before. (and add tests for that) Change-Id: I0fbbba1cfc67a265d09dd6cb738b73f0f6005247 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
96cab21383
commit
04c2c5bd80
@@ -104,3 +104,55 @@ func TestStateEqualFilteredIPFilter(t *testing.T) {
|
||||
t.Errorf("%+v == %+v when restricting to interesting interfaces and IPs", s1, s2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStateString(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
s *State
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "typical_linux",
|
||||
s: &State{
|
||||
DefaultRouteInterface: "eth0",
|
||||
Interface: map[string]Interface{
|
||||
"eth0": {
|
||||
Interface: &net.Interface{
|
||||
Flags: net.FlagUp,
|
||||
},
|
||||
},
|
||||
"wlan0": {
|
||||
Interface: &net.Interface{},
|
||||
},
|
||||
},
|
||||
InterfaceIPs: map[string][]netaddr.IPPrefix{
|
||||
"eth0": []netaddr.IPPrefix{
|
||||
netaddr.MustParseIPPrefix("10.0.0.2/8"),
|
||||
},
|
||||
},
|
||||
HaveV4: true,
|
||||
},
|
||||
want: `interfaces.State{defaultRoute=eth0 ifs={eth0:[10.0.0.2/8]} v4=true v6=false}`,
|
||||
},
|
||||
{
|
||||
name: "default_desc",
|
||||
s: &State{
|
||||
DefaultRouteInterface: "foo",
|
||||
Interface: map[string]Interface{
|
||||
"foo": {
|
||||
Desc: "a foo thing",
|
||||
},
|
||||
},
|
||||
},
|
||||
want: `interfaces.State{defaultRoute=foo (a foo thing) ifs={} v4=false v6=false}`,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := tt.s.String()
|
||||
if got != tt.want {
|
||||
t.Errorf("wrong\n got: %s\nwant: %s\n", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user