ipn/ipnlocal: add wireguard session state metrics + publish on IPN bus
Updates #19989 Updates tailscale/corp#42874 Change-Id: I843ed95bc7b0f5cd38ba1467332c6b022901e254 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
ae743642d9
commit
6596d237a3
@@ -4,6 +4,7 @@
|
||||
package ipn
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"tailscale.com/health"
|
||||
@@ -41,6 +42,41 @@ func TestNotifyString(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPeerWireGuardStateJSON(t *testing.T) {
|
||||
tests := []struct {
|
||||
state PeerWireGuardState
|
||||
json string
|
||||
}{
|
||||
{PeerWireGuardStateNone, `"none"`},
|
||||
{PeerWireGuardStateHandshake, `"handshake"`},
|
||||
{PeerWireGuardStateEstablished, `"established"`},
|
||||
{PeerWireGuardStateExpired, `"expired"`},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.state.String(), func(t *testing.T) {
|
||||
got, err := json.Marshal(tt.state)
|
||||
if err != nil {
|
||||
t.Fatalf("Marshal: %v", err)
|
||||
}
|
||||
if string(got) != tt.json {
|
||||
t.Errorf("Marshal(%v) = %s; want %s", tt.state, got, tt.json)
|
||||
}
|
||||
var back PeerWireGuardState
|
||||
if err := json.Unmarshal(got, &back); err != nil {
|
||||
t.Fatalf("Unmarshal: %v", err)
|
||||
}
|
||||
if back != tt.state {
|
||||
t.Errorf("round-trip = %v; want %v", back, tt.state)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
var bad PeerWireGuardState
|
||||
if err := json.Unmarshal([]byte(`"bogus"`), &bad); err == nil {
|
||||
t.Errorf("Unmarshal of bogus value did not return an error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateNotifyWatchOpt(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user