mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-22 21:08:38 +00:00

The AsDebugJSON method (used only for a LocalAPI debug call) always needed to be updated whenever a new controlknob was added. We had a test for it, which was nice, but it was a tedious step we don't need to do. Use reflect instead. Updates #14788 Change-Id: If59cd776920f3ce7c748f86ed2eddd9323039a0b Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
25 lines
548 B
Go
25 lines
548 B
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package controlknobs
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"tailscale.com/types/logger"
|
|
)
|
|
|
|
func TestAsDebugJSON(t *testing.T) {
|
|
var nilPtr *Knobs
|
|
if got := nilPtr.AsDebugJSON(); got != nil {
|
|
t.Errorf("AsDebugJSON(nil) = %v; want nil", got)
|
|
}
|
|
k := new(Knobs)
|
|
got := k.AsDebugJSON()
|
|
if want := reflect.TypeFor[Knobs]().NumField(); len(got) != want {
|
|
t.Errorf("AsDebugJSON map has %d fields; want %v", len(got), want)
|
|
}
|
|
t.Logf("Got: %v", logger.AsJSON(got))
|
|
}
|