mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 13:05:46 +00:00
7f174e84e6
Now callers (wgengine/monitor) don't need to mutate the state to remove boring interfaces before calling State.Equal. Instead, the methods to remove boring interfaces from the State are removed, as is the reflect-using Equal method itself, and in their place is a new EqualFiltered method that takes a func predicate to match interfaces to compare. And then the FilterInteresting predicate is added for use with EqualFiltered to do the job that that wgengine/monitor previously wanted. Now wgengine/monitor can keep the full interface state around, including the "boring" interfaces, which we'll need for peerapi on macOS/iOS to bind to the interface index of the utunN device. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
46 lines
928 B
Go
46 lines
928 B
Go
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package interfaces
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func TestGetState(t *testing.T) {
|
|
st, err := GetState()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
j, err := json.MarshalIndent(st, "", "\t")
|
|
if err != nil {
|
|
t.Errorf("JSON: %v", err)
|
|
}
|
|
t.Logf("Got: %s", j)
|
|
t.Logf("As string: %s", st)
|
|
|
|
st2, err := GetState()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if !st.EqualFiltered(st2, FilterAll) {
|
|
// let's assume nobody was changing the system network interfaces between
|
|
// the two GetState calls.
|
|
t.Fatal("two States back-to-back were not equal")
|
|
}
|
|
|
|
t.Logf("As string:\n\t%s", st)
|
|
}
|
|
|
|
func TestLikelyHomeRouterIP(t *testing.T) {
|
|
gw, my, ok := LikelyHomeRouterIP()
|
|
if !ok {
|
|
t.Logf("no result")
|
|
return
|
|
}
|
|
t.Logf("myIP = %v; gw = %v", my, gw)
|
|
}
|