mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-02 01:51:59 +00:00
health: move health metrics test to health_test
Updates #13420 Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
committed by
Kristoffer Dalby
parent
bac3af06f5
commit
41e56cedf8
@@ -7,11 +7,13 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"tailscale.com/tailcfg"
|
||||
"tailscale.com/types/opt"
|
||||
"tailscale.com/util/usermetric"
|
||||
)
|
||||
|
||||
func TestAppendWarnableDebugFlags(t *testing.T) {
|
||||
@@ -273,7 +275,7 @@ func TestShowUpdateWarnable(t *testing.T) {
|
||||
wantShow bool
|
||||
}{
|
||||
{
|
||||
desc: "nil CientVersion",
|
||||
desc: "nil ClientVersion",
|
||||
check: true,
|
||||
cv: nil,
|
||||
wantWarnable: nil,
|
||||
@@ -348,3 +350,47 @@ func TestShowUpdateWarnable(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthMetric(t *testing.T) {
|
||||
tests := []struct {
|
||||
desc string
|
||||
check bool
|
||||
apply opt.Bool
|
||||
cv *tailcfg.ClientVersion
|
||||
wantMetricCount int
|
||||
}{
|
||||
// When running in dev, and not initialising the client, there will be two warnings
|
||||
// by default:
|
||||
// - is-using-unstable-version
|
||||
// - wantrunning-false
|
||||
{
|
||||
desc: "base-warnings",
|
||||
check: true,
|
||||
cv: nil,
|
||||
wantMetricCount: 2,
|
||||
},
|
||||
// with: update-available
|
||||
{
|
||||
desc: "update-warning",
|
||||
check: true,
|
||||
cv: &tailcfg.ClientVersion{RunningLatest: false, LatestVersion: "1.2.3"},
|
||||
wantMetricCount: 3,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.desc, func(t *testing.T) {
|
||||
tr := &Tracker{
|
||||
checkForUpdates: tt.check,
|
||||
applyUpdates: tt.apply,
|
||||
latestVersion: tt.cv,
|
||||
}
|
||||
tr.SetMetricsRegistry(&usermetric.Registry{})
|
||||
if val := tr.metricHealthMessage.Get(metricHealthMessageLabel{Type: MetricLabelWarning}).String(); val != strconv.Itoa(tt.wantMetricCount) {
|
||||
t.Fatalf("metric value: %q, want: %q", val, strconv.Itoa(tt.wantMetricCount))
|
||||
}
|
||||
for _, w := range tr.CurrentState().Warnings {
|
||||
t.Logf("warning: %v", w)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user