integration: make debugJSON and execJSON methods

Go 1.27 allows type parameters on methods, so the container no longer has
to be passed as the first argument.
This commit is contained in:
Kristoffer Dalby
2026-08-25 09:43:43 +00:00
committed by Kristoffer Dalby
parent 60bab7633c
commit 245b81401c
2 changed files with 11 additions and 16 deletions
+6 -6
View File
@@ -1723,31 +1723,31 @@ func (t *HeadscaleInContainer) SendInterrupt() error {
}
func (t *HeadscaleInContainer) GetAllMapReponses() (map[types.NodeID][]tailcfg.MapResponse, error) {
return debugJSON[map[types.NodeID][]tailcfg.MapResponse](t, "mapresponses")
return t.debugJSON[map[types.NodeID][]tailcfg.MapResponse]("mapresponses")
}
// PrimaryRoutes fetches the primary routes from the debug endpoint.
func (t *HeadscaleInContainer) PrimaryRoutes() (*types.DebugRoutes, error) {
return debugJSON[*types.DebugRoutes](t, "routes")
return t.debugJSON[*types.DebugRoutes]("routes")
}
// DebugBatcher fetches the batcher debug information from the debug endpoint.
func (t *HeadscaleInContainer) DebugBatcher() (*hscontrol.DebugBatcherInfo, error) {
return debugJSON[*hscontrol.DebugBatcherInfo](t, "batcher")
return t.debugJSON[*hscontrol.DebugBatcherInfo]("batcher")
}
// DebugNodeStore fetches the [state.NodeStore] data from the debug endpoint.
func (t *HeadscaleInContainer) DebugNodeStore() (map[types.NodeID]types.Node, error) {
return debugJSON[map[types.NodeID]types.Node](t, "nodestore")
return t.debugJSON[map[types.NodeID]types.Node]("nodestore")
}
// DebugFilter fetches the current filter rules from the debug endpoint.
func (t *HeadscaleInContainer) DebugFilter() ([]tailcfg.FilterRule, error) {
return debugJSON[[]tailcfg.FilterRule](t, "filter")
return t.debugJSON[[]tailcfg.FilterRule]("filter")
}
// debugJSON fetches and decodes a JSON-returning debug endpoint by name.
func debugJSON[T any](t *HeadscaleInContainer, endpoint string) (T, error) {
func (t *HeadscaleInContainer) debugJSON[T any](endpoint string) (T, error) {
var res T
// Execute curl inside the container to access the debug endpoint locally
+5 -10
View File
@@ -954,8 +954,7 @@ func (t *TailscaleInContainer) MustIPv6() netip.Addr {
// fresh T, and returns the value alongside the raw JSON for callers that persist
// it. stderr is printed when the command fails. execErr and unmarshalErr provide
// the error context used in test diagnostics.
func execJSON[T any](
t *TailscaleInContainer,
func (t *TailscaleInContainer) execJSON[T any](
command []string,
execErr, unmarshalErr string,
) (*T, string, error) {
@@ -983,8 +982,7 @@ func (t *TailscaleInContainer) Status(save ...bool) (*ipnstate.Status, error) {
"--json",
}
status, raw, err := execJSON[ipnstate.Status](
t,
status, raw, err := t.execJSON[ipnstate.Status](
command,
"executing tailscale status command",
"unmarshalling tailscale status",
@@ -1040,8 +1038,7 @@ func (t *TailscaleInContainer) Netmap() (*netmap.NetworkMap, error) {
"netmap",
}
nm, raw, err := execJSON[netmap.NetworkMap](
t,
nm, raw, err := t.execJSON[netmap.NetworkMap](
command,
"executing tailscale debug netmap command",
"unmarshalling tailscale netmap",
@@ -1165,8 +1162,7 @@ func (t *TailscaleInContainer) DebugDERPRegion(region string) (*ipnstate.DebugDE
region,
}
report, _, err := execJSON[ipnstate.DebugDERPRegionReport](
t,
report, _, err := t.execJSON[ipnstate.DebugDERPRegionReport](
command,
"executing tailscale debug derp command",
"unmarshalling tailscale derp region report",
@@ -1186,8 +1182,7 @@ func (t *TailscaleInContainer) Netcheck() (*netcheck.Report, error) {
"--format=json",
}
nm, _, err := execJSON[netcheck.Report](
t,
nm, _, err := t.execJSON[netcheck.Report](
command,
"executing tailscale debug netcheck command",
"unmarshalling tailscale netcheck",