From 245b81401c0f32bf1d211dcea151a78515c743f7 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Tue, 25 Aug 2026 09:43:43 +0000 Subject: [PATCH] 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. --- integration/hsic/hsic.go | 12 ++++++------ integration/tsic/tsic.go | 15 +++++---------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/integration/hsic/hsic.go b/integration/hsic/hsic.go index d37bac9af..bd4b539aa 100644 --- a/integration/hsic/hsic.go +++ b/integration/hsic/hsic.go @@ -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 diff --git a/integration/tsic/tsic.go b/integration/tsic/tsic.go index 3e19d2b14..1e5dd3f33 100644 --- a/integration/tsic/tsic.go +++ b/integration/tsic/tsic.go @@ -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",