mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-02 01:51:59 +00:00
doctor: add package for running in-depth healthchecks; use in bugreport (#5413)
Change-Id: Iaa4e5b021a545447f319cfe8b3da2bd3e5e5782b Signed-off-by: Andrew Dunham <andrew@du.nham.ca>
This commit is contained in:
50
doctor/doctor_test.go
Normal file
50
doctor/doctor_test.go
Normal file
@@ -0,0 +1,50 @@
|
||||
// Copyright (c) 2022 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 doctor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
qt "github.com/frankban/quicktest"
|
||||
"tailscale.com/types/logger"
|
||||
)
|
||||
|
||||
func TestRunChecks(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
var (
|
||||
mu sync.Mutex
|
||||
lines []string
|
||||
)
|
||||
logf := func(format string, args ...any) {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
lines = append(lines, fmt.Sprintf(format, args...))
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
RunChecks(ctx, logf,
|
||||
testCheck1{},
|
||||
CheckFunc("testcheck2", func(_ context.Context, log logger.Logf) error {
|
||||
log("check 2")
|
||||
return nil
|
||||
}),
|
||||
)
|
||||
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
c.Assert(lines, qt.Contains, "testcheck1: check 1")
|
||||
c.Assert(lines, qt.Contains, "testcheck2: check 2")
|
||||
}
|
||||
|
||||
type testCheck1 struct{}
|
||||
|
||||
func (t testCheck1) Name() string { return "testcheck1" }
|
||||
func (t testCheck1) Run(_ context.Context, log logger.Logf) error {
|
||||
log("check 1")
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user