mirror of
https://github.com/juanfont/headscale.git
synced 2026-02-07 20:04:00 +01:00
integration: add nolint:err113 comments for test infrastructure
Add nolint:err113 comments to integration test infrastructure code where dynamic errors are appropriate for debugging test failures. These errors include context-specific information like container names, hostnames, and test states that help diagnose issues. Files updated: - derp_verify_endpoint_test.go: DERP verification errors - helpers.go: command execution and user lookup errors - hsic/hsic.go: database export errors - scenario.go: network and HTTP client validation errors - tsic/tsic.go: container status and peer validation errors Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
3c3e39c737
commit
43349553f2
@ -115,7 +115,7 @@ func DERPVerify(
|
||||
if m, err := c.Recv(); err != nil {
|
||||
result = fmt.Errorf("client first Recv: %w", err)
|
||||
} else if v, ok := m.(derp.ServerInfoMessage); !ok {
|
||||
result = fmt.Errorf("client first Recv was unexpected type %T", v)
|
||||
result = fmt.Errorf("client first Recv was unexpected type %T", v) //nolint:err113
|
||||
}
|
||||
|
||||
if expectSuccess && result != nil {
|
||||
|
||||
@ -817,7 +817,7 @@ func assertCommandOutputContains(t *testing.T, c TailscaleClient, command []stri
|
||||
}
|
||||
|
||||
if !strings.Contains(stdout, contains) {
|
||||
return struct{}{}, fmt.Errorf("executing command, expected string %q not found in %q", contains, stdout)
|
||||
return struct{}{}, fmt.Errorf("executing command, expected string %q not found in %q", contains, stdout) //nolint:err113
|
||||
}
|
||||
|
||||
return struct{}{}, nil
|
||||
@ -990,7 +990,7 @@ func GetUserByName(headscale ControlServer, username string) (*v1.User, error) {
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("user %s not found", username)
|
||||
return nil, fmt.Errorf("user %s not found", username) //nolint:err113
|
||||
}
|
||||
|
||||
// FindNewClient finds a client that is in the new list but not in the original list.
|
||||
@ -1052,7 +1052,7 @@ func (s *Scenario) AddAndLoginClient(
|
||||
}
|
||||
|
||||
if len(updatedClients) != len(originalClients)+1 {
|
||||
return struct{}{}, fmt.Errorf("expected %d clients, got %d", len(originalClients)+1, len(updatedClients))
|
||||
return struct{}{}, fmt.Errorf("expected %d clients, got %d", len(originalClients)+1, len(updatedClients)) //nolint:err113
|
||||
}
|
||||
|
||||
newClient, err = FindNewClient(originalClients, updatedClients)
|
||||
|
||||
@ -872,7 +872,7 @@ func (t *HeadscaleInContainer) SaveDatabase(savePath string) error {
|
||||
}
|
||||
|
||||
if strings.TrimSpace(schemaCheck) == "" {
|
||||
return errors.New("database file exists but has no schema (empty database)")
|
||||
return errors.New("database file exists but has no schema (empty database)") //nolint:err113
|
||||
}
|
||||
|
||||
tarFile, err := t.FetchPath("/tmp/integration_test_db.sqlite3")
|
||||
@ -924,7 +924,7 @@ func (t *HeadscaleInContainer) SaveDatabase(savePath string) error {
|
||||
|
||||
// Check if we actually wrote something
|
||||
if written == 0 {
|
||||
return fmt.Errorf(
|
||||
return fmt.Errorf( //nolint:err113
|
||||
"database file is empty (size: %d, header size: %d)",
|
||||
written,
|
||||
header.Size,
|
||||
@ -935,7 +935,7 @@ func (t *HeadscaleInContainer) SaveDatabase(savePath string) error {
|
||||
}
|
||||
}
|
||||
|
||||
return errors.New("no regular file found in database tar archive")
|
||||
return errors.New("no regular file found in database tar archive") //nolint:err113
|
||||
}
|
||||
|
||||
// Execute runs a command inside the Headscale container and returns the
|
||||
|
||||
@ -203,7 +203,7 @@ func NewScenario(spec ScenarioSpec) (*Scenario, error) {
|
||||
|
||||
for _, user := range users {
|
||||
if n2, ok := userToNetwork[user]; ok {
|
||||
return nil, fmt.Errorf("users can only have nodes placed in one network: %s into %s but already in %s", user, network.Network.Name, n2.Network.Name)
|
||||
return nil, fmt.Errorf("users can only have nodes placed in one network: %s into %s but already in %s", user, network.Network.Name, n2.Network.Name) //nolint:err113
|
||||
}
|
||||
|
||||
mak.Set(&userToNetwork, user, network)
|
||||
@ -280,7 +280,7 @@ func (s *Scenario) Networks() []*dockertest.Network {
|
||||
func (s *Scenario) Network(name string) (*dockertest.Network, error) {
|
||||
net, ok := s.networks[s.prefixedNetworkName(name)]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("no network named: %s", name)
|
||||
return nil, fmt.Errorf("no network named: %s", name) //nolint:err113
|
||||
}
|
||||
|
||||
return net, nil
|
||||
@ -289,11 +289,11 @@ func (s *Scenario) Network(name string) (*dockertest.Network, error) {
|
||||
func (s *Scenario) SubnetOfNetwork(name string) (*netip.Prefix, error) {
|
||||
net, ok := s.networks[s.prefixedNetworkName(name)]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("no network named: %s", name)
|
||||
return nil, fmt.Errorf("no network named: %s", name) //nolint:err113
|
||||
}
|
||||
|
||||
if len(net.Network.IPAM.Config) == 0 {
|
||||
return nil, fmt.Errorf("no IPAM config found in network: %s", name)
|
||||
return nil, fmt.Errorf("no IPAM config found in network: %s", name) //nolint:err113
|
||||
}
|
||||
|
||||
pref, err := netip.ParsePrefix(net.Network.IPAM.Config[0].Subnet)
|
||||
@ -307,7 +307,7 @@ func (s *Scenario) SubnetOfNetwork(name string) (*netip.Prefix, error) {
|
||||
func (s *Scenario) Services(name string) ([]*dockertest.Resource, error) {
|
||||
res, ok := s.extraServices[s.prefixedNetworkName(name)]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("no network named: %s", name)
|
||||
return nil, fmt.Errorf("no network named: %s", name) //nolint:err113
|
||||
}
|
||||
|
||||
return res, nil
|
||||
@ -1087,11 +1087,11 @@ func doLoginURLWithClient(hostname string, loginURL *url.URL, hc *http.Client, f
|
||||
error,
|
||||
) {
|
||||
if hc == nil {
|
||||
return "", nil, fmt.Errorf("%s http client is nil", hostname)
|
||||
return "", nil, fmt.Errorf("%s http client is nil", hostname) //nolint:err113
|
||||
}
|
||||
|
||||
if loginURL == nil {
|
||||
return "", nil, fmt.Errorf("%s login url is nil", hostname)
|
||||
return "", nil, fmt.Errorf("%s login url is nil", hostname) //nolint:err113
|
||||
}
|
||||
|
||||
log.Printf("%s logging in with url: %s", hostname, loginURL.String())
|
||||
@ -1138,13 +1138,13 @@ func doLoginURLWithClient(hostname string, loginURL *url.URL, hc *http.Client, f
|
||||
if followRedirects && resp.StatusCode != http.StatusOK {
|
||||
log.Printf("body: %s", body)
|
||||
|
||||
return body, redirectURL, fmt.Errorf("%s unexpected status code %d", hostname, resp.StatusCode)
|
||||
return body, redirectURL, fmt.Errorf("%s unexpected status code %d", hostname, resp.StatusCode) //nolint:err113
|
||||
}
|
||||
|
||||
if resp.StatusCode >= http.StatusBadRequest {
|
||||
log.Printf("body: %s", body)
|
||||
|
||||
return body, redirectURL, fmt.Errorf("%s unexpected status code %d", hostname, resp.StatusCode)
|
||||
return body, redirectURL, fmt.Errorf("%s unexpected status code %d", hostname, resp.StatusCode) //nolint:err113
|
||||
}
|
||||
|
||||
if hc.Jar != nil {
|
||||
@ -1529,7 +1529,7 @@ func Webservice(s *Scenario, networkName string) (*dockertest.Resource, error) {
|
||||
|
||||
network, ok := s.networks[s.prefixedNetworkName(networkName)]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("network does not exist: %s", networkName)
|
||||
return nil, fmt.Errorf("network does not exist: %s", networkName) //nolint:err113
|
||||
}
|
||||
|
||||
webOpts := &dockertest.RunOptions{
|
||||
|
||||
@ -336,7 +336,7 @@ func New(
|
||||
}
|
||||
|
||||
if tsic.network == nil {
|
||||
return nil, fmt.Errorf("no network set, called from: \n%s", string(debug.Stack()))
|
||||
return nil, fmt.Errorf("no network set, called from: \n%s", string(debug.Stack())) //nolint:err113
|
||||
}
|
||||
|
||||
tailscaleOptions := &dockertest.RunOptions{
|
||||
@ -718,7 +718,7 @@ func (t *TailscaleInContainer) Logout() error {
|
||||
|
||||
stdout, stderr, _ = t.Execute([]string{"tailscale", "status"})
|
||||
if !strings.Contains(stdout+stderr, "Logged out.") {
|
||||
return fmt.Errorf("logging out, stdout: %s, stderr: %s", stdout, stderr)
|
||||
return fmt.Errorf("logging out, stdout: %s, stderr: %s", stdout, stderr) //nolint:err113
|
||||
}
|
||||
|
||||
return t.waitForBackendState("NeedsLogin", integrationutil.PeerSyncTimeout())
|
||||
@ -830,7 +830,7 @@ func (t *TailscaleInContainer) IPs() ([]netip.Addr, error) {
|
||||
}
|
||||
|
||||
if len(ips) == 0 {
|
||||
return nil, fmt.Errorf("no IPs returned yet for %s", t.hostname)
|
||||
return nil, fmt.Errorf("no IPs returned yet for %s", t.hostname) //nolint:err113
|
||||
}
|
||||
|
||||
return ips, nil
|
||||
@ -864,7 +864,7 @@ func (t *TailscaleInContainer) IPv4() (netip.Addr, error) {
|
||||
}
|
||||
}
|
||||
|
||||
return netip.Addr{}, fmt.Errorf("no IPv4 address found for %s", t.hostname)
|
||||
return netip.Addr{}, fmt.Errorf("no IPv4 address found for %s", t.hostname) //nolint:err113
|
||||
}
|
||||
|
||||
func (t *TailscaleInContainer) MustIPv4() netip.Addr {
|
||||
@ -1211,7 +1211,7 @@ func (t *TailscaleInContainer) waitForBackendState(state string, timeout time.Du
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return fmt.Errorf("timeout waiting for backend state %s on %s after %v", state, t.hostname, timeout)
|
||||
return fmt.Errorf("timeout waiting for backend state %s on %s after %v", state, t.hostname, timeout) //nolint:err113
|
||||
case <-ticker.C:
|
||||
status, err := t.Status()
|
||||
if err != nil {
|
||||
@ -1256,7 +1256,7 @@ func (t *TailscaleInContainer) WaitForPeers(expected int, timeout, retryInterval
|
||||
return fmt.Errorf("timeout waiting for %d peers on %s after %v, errors: %w", expected, t.hostname, timeout, multierr.New(lastErrs...))
|
||||
}
|
||||
|
||||
return fmt.Errorf("timeout waiting for %d peers on %s after %v", expected, t.hostname, timeout)
|
||||
return fmt.Errorf("timeout waiting for %d peers on %s after %v", expected, t.hostname, timeout) //nolint:err113
|
||||
case <-ticker.C:
|
||||
status, err := t.Status()
|
||||
if err != nil {
|
||||
@ -1284,15 +1284,15 @@ func (t *TailscaleInContainer) WaitForPeers(expected int, timeout, retryInterval
|
||||
peer := status.Peer[peerKey]
|
||||
|
||||
if !peer.Online {
|
||||
peerErrors = append(peerErrors, fmt.Errorf("[%s] peer count correct, but %s is not online", t.hostname, peer.HostName))
|
||||
peerErrors = append(peerErrors, fmt.Errorf("[%s] peer count correct, but %s is not online", t.hostname, peer.HostName)) //nolint:err113
|
||||
}
|
||||
|
||||
if peer.HostName == "" {
|
||||
peerErrors = append(peerErrors, fmt.Errorf("[%s] peer count correct, but %s does not have a Hostname", t.hostname, peer.HostName))
|
||||
peerErrors = append(peerErrors, fmt.Errorf("[%s] peer count correct, but %s does not have a Hostname", t.hostname, peer.HostName)) //nolint:err113
|
||||
}
|
||||
|
||||
if peer.Relay == "" {
|
||||
peerErrors = append(peerErrors, fmt.Errorf("[%s] peer count correct, but %s does not have a DERP", t.hostname, peer.HostName))
|
||||
peerErrors = append(peerErrors, fmt.Errorf("[%s] peer count correct, but %s does not have a DERP", t.hostname, peer.HostName)) //nolint:err113
|
||||
}
|
||||
}
|
||||
|
||||
@ -1566,7 +1566,7 @@ func (t *TailscaleInContainer) ReadFile(path string) ([]byte, error) {
|
||||
}
|
||||
|
||||
if !strings.Contains(path, hdr.Name) {
|
||||
return nil, fmt.Errorf("file not found in tar archive, looking for: %s, header was: %s", path, hdr.Name)
|
||||
return nil, fmt.Errorf("file not found in tar archive, looking for: %s, header was: %s", path, hdr.Name) //nolint:err113
|
||||
}
|
||||
|
||||
if _, err := io.Copy(&out, tr); err != nil {
|
||||
@ -1578,7 +1578,7 @@ func (t *TailscaleInContainer) ReadFile(path string) ([]byte, error) {
|
||||
}
|
||||
|
||||
if out.Len() == 0 {
|
||||
return nil, errors.New("file is empty")
|
||||
return nil, errors.New("file is empty") //nolint:err113
|
||||
}
|
||||
|
||||
return out.Bytes(), nil
|
||||
@ -1617,7 +1617,7 @@ func (t *TailscaleInContainer) GetNodePrivateKey() (*key.NodePrivate, error) {
|
||||
// This is useful for verifying that policy changes have propagated to the client.
|
||||
func (t *TailscaleInContainer) PacketFilter() ([]filter.Match, error) {
|
||||
if !util.TailscaleVersionNewerOrEqual("1.56", t.version) {
|
||||
return nil, fmt.Errorf("tsic.PacketFilter() requires Tailscale 1.56+, current version: %s", t.version)
|
||||
return nil, fmt.Errorf("tsic.PacketFilter() requires Tailscale 1.56+, current version: %s", t.version) //nolint:err113
|
||||
}
|
||||
|
||||
nm, err := t.Netmap()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user