2023-01-27 21:37:20 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2022-11-13 15:32:37 +00:00
|
|
|
|
|
|
|
package health
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
2023-09-09 16:55:57 +00:00
|
|
|
|
|
|
|
"tailscale.com/util/set"
|
2022-11-13 15:32:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAppendWarnableDebugFlags(t *testing.T) {
|
|
|
|
resetWarnables()
|
|
|
|
|
2024-04-16 20:15:13 +00:00
|
|
|
for i := range 10 {
|
2022-11-13 15:32:37 +00:00
|
|
|
w := NewWarnable(WithMapDebugFlag(fmt.Sprint(i)))
|
|
|
|
if i%2 == 0 {
|
|
|
|
w.Set(errors.New("boom"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
want := []string{"z", "y", "0", "2", "4", "6", "8"}
|
|
|
|
|
|
|
|
var got []string
|
2024-04-16 20:15:13 +00:00
|
|
|
for range 20 {
|
2022-11-13 15:32:37 +00:00
|
|
|
got = append(got[:0], "z", "y")
|
|
|
|
got = AppendWarnableDebugFlags(got)
|
|
|
|
if !reflect.DeepEqual(got, want) {
|
|
|
|
t.Fatalf("AppendWarnableDebugFlags = %q; want %q", got, want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func resetWarnables() {
|
|
|
|
mu.Lock()
|
|
|
|
defer mu.Unlock()
|
2023-09-09 16:55:57 +00:00
|
|
|
warnables = set.Set[*Warnable]{}
|
2022-11-13 15:32:37 +00:00
|
|
|
}
|