mirror of
https://github.com/juanfont/headscale.git
synced 2026-01-23 02:24:10 +00:00
all: fix staticcheck issues
- Apply De Morgan's law to simplify condition in types.go - Simplify return statement in batcher_test.go - Fix potential nil pointer dereference by using t.Fatal in util_test.go - Remove unused variable assignment in auth_oidc_test.go - Remove duplicate tarReader assignment in hsic.go - Add empty line after embedded field in batcher_test.go and types.go Note: Many staticcheck SA4006 warnings are false positives due to Go 1.26's new `new(value)` syntax which creates a pointer to a value. The staticcheck tool hasn't been updated to understand this syntax.
This commit is contained in:
parent
956bcb3680
commit
676273ee9d
5 changed files with 10 additions and 15 deletions
|
|
@ -36,6 +36,7 @@ type batcherTestCase struct {
|
|||
// that would normally be sent by poll.go in production.
|
||||
type testBatcherWrapper struct {
|
||||
Batcher
|
||||
|
||||
state *state.State
|
||||
}
|
||||
|
||||
|
|
@ -81,12 +82,7 @@ func (t *testBatcherWrapper) RemoveNode(id types.NodeID, c chan<- *tailcfg.MapRe
|
|||
}
|
||||
|
||||
// Finally remove from the real batcher
|
||||
removed := t.Batcher.RemoveNode(id, c)
|
||||
if !removed {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
return t.Batcher.RemoveNode(id, c)
|
||||
}
|
||||
|
||||
// wrapBatcherForTest wraps a batcher with test-specific behavior.
|
||||
|
|
|
|||
|
|
@ -596,6 +596,7 @@ type Alias interface {
|
|||
|
||||
type AliasWithPorts struct {
|
||||
Alias
|
||||
|
||||
Ports []tailcfg.PortRange
|
||||
}
|
||||
|
||||
|
|
@ -2107,7 +2108,7 @@ func validateProtocolPortCompatibility(protocol Protocol, destinations []AliasWi
|
|||
for _, dst := range destinations {
|
||||
for _, portRange := range dst.Ports {
|
||||
// Check if it's not a wildcard port (0-65535)
|
||||
if !(portRange.First == 0 && portRange.Last == 65535) {
|
||||
if portRange.First != 0 || portRange.Last != 65535 {
|
||||
return fmt.Errorf("protocol %q does not support specific ports; only \"*\" is allowed", protocol)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1103,7 +1103,7 @@ func TestEnsureHostnameWithHostinfo(t *testing.T) {
|
|||
wantHostname: "test-node",
|
||||
checkHostinfo: func(t *testing.T, hi *tailcfg.Hostinfo) {
|
||||
if hi == nil {
|
||||
t.Error("hostinfo should not be nil")
|
||||
t.Fatal("hostinfo should not be nil")
|
||||
}
|
||||
|
||||
if hi.Hostname != "test-node" {
|
||||
|
|
@ -1149,7 +1149,7 @@ func TestEnsureHostnameWithHostinfo(t *testing.T) {
|
|||
wantHostname: "node-nkey1234",
|
||||
checkHostinfo: func(t *testing.T, hi *tailcfg.Hostinfo) {
|
||||
if hi == nil {
|
||||
t.Error("hostinfo should not be nil")
|
||||
t.Fatal("hostinfo should not be nil")
|
||||
}
|
||||
|
||||
if hi.Hostname != "node-nkey1234" {
|
||||
|
|
@ -1165,7 +1165,7 @@ func TestEnsureHostnameWithHostinfo(t *testing.T) {
|
|||
wantHostname: "unknown-node",
|
||||
checkHostinfo: func(t *testing.T, hi *tailcfg.Hostinfo) {
|
||||
if hi == nil {
|
||||
t.Error("hostinfo should not be nil")
|
||||
t.Fatal("hostinfo should not be nil")
|
||||
}
|
||||
|
||||
if hi.Hostname != "unknown-node" {
|
||||
|
|
@ -1183,7 +1183,7 @@ func TestEnsureHostnameWithHostinfo(t *testing.T) {
|
|||
wantHostname: "unknown-node",
|
||||
checkHostinfo: func(t *testing.T, hi *tailcfg.Hostinfo) {
|
||||
if hi == nil {
|
||||
t.Error("hostinfo should not be nil")
|
||||
t.Fatal("hostinfo should not be nil")
|
||||
}
|
||||
|
||||
if hi.Hostname != "unknown-node" {
|
||||
|
|
|
|||
|
|
@ -1052,7 +1052,7 @@ func TestOIDCMultipleOpenedLoginUrls(t *testing.T) {
|
|||
require.NotEqual(t, redirect1.String(), redirect2.String())
|
||||
|
||||
// complete auth with the first opened "browser tab"
|
||||
_, redirect1, err = doLoginURLWithClient(ts.Hostname(), redirect1, loginClient, true)
|
||||
_, _, err = doLoginURLWithClient(ts.Hostname(), redirect1, loginClient, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
listUsers, err = headscale.ListUsers()
|
||||
|
|
|
|||
|
|
@ -721,8 +721,6 @@ func extractTarToDirectory(tarData []byte, targetDir string) error {
|
|||
return fmt.Errorf("failed to create directory %s: %w", targetDir, err)
|
||||
}
|
||||
|
||||
tarReader := tar.NewReader(bytes.NewReader(tarData))
|
||||
|
||||
// Find the top-level directory to strip
|
||||
var topLevelDir string
|
||||
|
||||
|
|
@ -743,7 +741,7 @@ func extractTarToDirectory(tarData []byte, targetDir string) error {
|
|||
}
|
||||
}
|
||||
|
||||
tarReader = tar.NewReader(bytes.NewReader(tarData))
|
||||
tarReader := tar.NewReader(bytes.NewReader(tarData))
|
||||
for {
|
||||
header, err := tarReader.Next()
|
||||
if err == io.EOF {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue