control/controlclient,health: add tests for control health tracking

Updates tailscale/corp#27759

Signed-off-by: James Sanderson <jsanderson@tailscale.com>
This commit is contained in:
James Sanderson
2025-04-29 11:37:12 +01:00
committed by James 'zofrex' Sanderson
parent ac1215c7e0
commit 1f1c323eeb
3 changed files with 130 additions and 3 deletions

View File

@@ -17,6 +17,7 @@ import (
"github.com/google/go-cmp/cmp"
"go4.org/mem"
"tailscale.com/control/controlknobs"
"tailscale.com/health"
"tailscale.com/tailcfg"
"tailscale.com/tstest"
"tailscale.com/tstime"
@@ -1136,3 +1137,34 @@ func BenchmarkMapSessionDelta(b *testing.B) {
})
}
}
// TestNetmapHealthIntegration checks that we get the expected health warnings
// from processing a map response and passing the NetworkMap to a health tracker
func TestNetmapHealthIntegration(t *testing.T) {
ms := newTestMapSession(t, nil)
ht := health.Tracker{}
ht.SetIPNState("NeedsLogin", true)
ht.GotStreamedMapResponse()
nm := ms.netmapForResponse(&tailcfg.MapResponse{
Health: []string{"Test message"},
})
ht.SetControlHealth(nm.ControlHealth)
state := ht.CurrentState()
warning, ok := state.Warnings["control-health"]
if !ok {
t.Fatal("no warning found in current state with code 'control-health'")
}
if got, want := warning.Title, "Coordination server reports an issue"; got != want {
t.Errorf("warning.Title = %q, want %q", got, want)
}
if got, want := warning.Severity, health.SeverityMedium; got != want {
t.Errorf("warning.Severity = %s, want %s", got, want)
}
if got, want := warning.Text, "The coordination server is reporting an health issue: Test message"; got != want {
t.Errorf("warning.Text = %q, want %q", got, want)
}
}