headscale/cmd/mapresponses/main.go
Kristoffer Dalby f969745db4 integration: define sentinel errors for err113 compliance
Add sentinel errors across integration test infrastructure and test
files to comply with err113 linter requirements. This replaces inline
dynamic errors with wrapped static sentinel errors.

Files updated:
- integration/tsic/tsic.go: Add errNoNetworkSet, errLogoutFailed,
  errNoIPsReturned, errNoIPv4AddressFound, errBackendStateTimeout,
  errPeerWaitTimeout, errPeerNotOnline, errPeerNoHostname,
  errPeerNoDERP, errFileEmpty, errTailscaleVersionRequired
- integration/scenario.go: Add errUserAlreadyInNetwork, errNoNetworkNamed,
  errNoIPAMConfig, errHTTPClientNil, errLoginURLNil,
  errUnexpectedStatusCode, errNetworkDoesNotExist
- integration/helpers.go: Add errExpectedStringNotFound, errUserNotFound,
  errNoNewClientFound, errUnexpectedClientCount
- integration/hsic/hsic.go: Add errDatabaseEmptySchema, errDatabaseFileEmpty,
  errNoRegularFileInTar
- integration/derp_verify_endpoint_test.go: Add errUnexpectedRecvType
- cmd/mapresponses/main.go: Add errDirectoryRequired
- hscontrol/auth_test.go: Add errNodeNotFoundAfterSetup, errInvalidAuthURLFormat
- hscontrol/state/node_store_test.go: Add errTestUpdateNodeFailed,
  errTestGetNodeFailed, errTestPutNodeFailed
2026-01-21 15:54:38 +00:00

65 lines
1.5 KiB
Go

package main
import (
"encoding/json"
"errors"
"fmt"
"os"
"github.com/creachadair/command"
"github.com/creachadair/flax"
"github.com/juanfont/headscale/hscontrol/mapper"
"github.com/juanfont/headscale/integration/integrationutil"
)
var errDirectoryRequired = errors.New("directory is required")
type MapConfig struct {
Directory string `flag:"directory,Directory to read map responses from"`
}
var mapConfig MapConfig
func main() {
root := command.C{
Name: "mapresponses",
Help: "MapResponses is a tool to map and compare map responses from a directory",
Commands: []*command.C{
{
Name: "online",
Help: "",
Usage: "run [test-pattern] [flags]",
SetFlags: command.Flags(flax.MustBind, &mapConfig),
Run: runOnline,
},
command.HelpCommand(nil),
},
}
env := root.NewEnv(nil).MergeFlags(true)
command.RunOrFail(env, os.Args[1:])
}
// runIntegrationTest executes the integration test workflow.
func runOnline(env *command.Env) error {
if mapConfig.Directory == "" {
return errDirectoryRequired
}
resps, err := mapper.ReadMapResponsesFromDirectory(mapConfig.Directory)
if err != nil {
return fmt.Errorf("reading map responses from directory: %w", err)
}
expected := integrationutil.BuildExpectedOnlineMap(resps)
out, err := json.MarshalIndent(expected, "", " ")
if err != nil {
return fmt.Errorf("marshaling expected online map: %w", err)
}
os.Stderr.Write(out)
os.Stderr.Write([]byte("\n"))
return nil
}