mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
b1867457a6
Change-Id: Iaa4e5b021a545447f319cfe8b3da2bd3e5e5782b Signed-off-by: Andrew Dunham <andrew@du.nham.ca>
51 lines
1.0 KiB
Go
51 lines
1.0 KiB
Go
// 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
|
|
}
|