Fix linting errors
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package access
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
@@ -86,7 +87,7 @@ func registerAPIEndpoints() error {
|
||||
DataFunc: func(ar *api.Request) (data []byte, err error) {
|
||||
featureID, ok := ar.URLVars["id"]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid feature id")
|
||||
return nil, errors.New("invalid feature id")
|
||||
}
|
||||
|
||||
for _, feature := range features {
|
||||
@@ -95,7 +96,7 @@ func registerAPIEndpoints() error {
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("feature id not found")
|
||||
return nil, errors.New("feature id not found")
|
||||
},
|
||||
}); err != nil {
|
||||
return err
|
||||
|
||||
@@ -128,7 +128,7 @@ findCandidates:
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to connect to a new home hub - tried %d hubs: %w", tries+1, err)
|
||||
}
|
||||
return fmt.Errorf("no home hub candidates available")
|
||||
return errors.New("no home hub candidates available")
|
||||
}
|
||||
|
||||
func connectToHomeHub(ctx context.Context, dst *hub.Hub) error {
|
||||
@@ -200,7 +200,7 @@ func connectToHomeHub(ctx context.Context, dst *hub.Hub) error {
|
||||
// Set new home on map.
|
||||
ok := navigator.Main.SetHome(dst.ID, homeTerminal)
|
||||
if !ok {
|
||||
return fmt.Errorf("failed to set home hub on map")
|
||||
return errors.New("failed to set home hub on map")
|
||||
}
|
||||
|
||||
// Assign crane to home hub in order to query it later.
|
||||
|
||||
@@ -82,7 +82,7 @@ func (t *Tunnel) connectWorker(ctx context.Context) (err error) {
|
||||
// TODO: Clean this up.
|
||||
t.connInfo.Lock()
|
||||
defer t.connInfo.Unlock()
|
||||
t.connInfo.Failed(fmt.Sprintf("SPN failed to establish route: %s", err), "")
|
||||
t.connInfo.Failed("SPN failed to establish route: "+err.Error(), "")
|
||||
t.connInfo.Save()
|
||||
|
||||
tracer.Warningf("spn/crew: failed to establish route for %s: %s", t.connInfo, err)
|
||||
@@ -97,7 +97,7 @@ func (t *Tunnel) connectWorker(ctx context.Context) (err error) {
|
||||
|
||||
t.connInfo.Lock()
|
||||
defer t.connInfo.Unlock()
|
||||
t.connInfo.Failed(fmt.Sprintf("SPN failed to initialize data tunnel (connect op): %s", tErr.Error()), "")
|
||||
t.connInfo.Failed("SPN failed to initialize data tunnel (connect op): "+tErr.Error(), "")
|
||||
t.connInfo.Save()
|
||||
|
||||
// TODO: try with another route?
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestCheckStringFormat(t *testing.T) {
|
||||
@@ -48,9 +48,9 @@ func TestCheckStringFormat(t *testing.T) {
|
||||
|
||||
for testCharacter, isPermitted := range testSet {
|
||||
if isPermitted {
|
||||
assert.NoError(t, checkStringFormat(fmt.Sprintf("test character %q", testCharacter), testCharacter, 3))
|
||||
require.NoError(t, checkStringFormat(fmt.Sprintf("test character %q", testCharacter), testCharacter, 3))
|
||||
} else {
|
||||
assert.Error(t, checkStringFormat(fmt.Sprintf("test character %q", testCharacter), testCharacter, 3))
|
||||
require.Error(t, checkStringFormat(fmt.Sprintf("test character %q", testCharacter), testCharacter, 3))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,22 +59,22 @@ func TestCheckIPFormat(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// IPv4
|
||||
assert.NoError(t, checkIPFormat("test IP 1.1.1.1", net.IPv4(1, 1, 1, 1)))
|
||||
assert.NoError(t, checkIPFormat("test IP 192.168.1.1", net.IPv4(192, 168, 1, 1)))
|
||||
assert.Error(t, checkIPFormat("test IP 255.0.0.1", net.IPv4(255, 0, 0, 1)))
|
||||
require.NoError(t, checkIPFormat("test IP 1.1.1.1", net.IPv4(1, 1, 1, 1)))
|
||||
require.NoError(t, checkIPFormat("test IP 192.168.1.1", net.IPv4(192, 168, 1, 1)))
|
||||
require.Error(t, checkIPFormat("test IP 255.0.0.1", net.IPv4(255, 0, 0, 1)))
|
||||
|
||||
// IPv6
|
||||
assert.NoError(t, checkIPFormat("test IP ::1", net.ParseIP("::1")))
|
||||
assert.NoError(t, checkIPFormat("test IP 2606:4700:4700::1111", net.ParseIP("2606:4700:4700::1111")))
|
||||
require.NoError(t, checkIPFormat("test IP ::1", net.ParseIP("::1")))
|
||||
require.NoError(t, checkIPFormat("test IP 2606:4700:4700::1111", net.ParseIP("2606:4700:4700::1111")))
|
||||
|
||||
// Invalid
|
||||
assert.Error(t, checkIPFormat("test IP with length 3", net.IP([]byte{0, 0, 0})))
|
||||
assert.Error(t, checkIPFormat("test IP with length 5", net.IP([]byte{0, 0, 0, 0, 0})))
|
||||
assert.Error(t, checkIPFormat(
|
||||
require.Error(t, checkIPFormat("test IP with length 3", net.IP([]byte{0, 0, 0})))
|
||||
require.Error(t, checkIPFormat("test IP with length 5", net.IP([]byte{0, 0, 0, 0, 0})))
|
||||
require.Error(t, checkIPFormat(
|
||||
"test IP with length 15",
|
||||
net.IP([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}),
|
||||
))
|
||||
assert.Error(t, checkIPFormat(
|
||||
require.Error(t, checkIPFormat(
|
||||
"test IP with length 17",
|
||||
net.IP([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}),
|
||||
))
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func parseT(t *testing.T, definition string) *Transport {
|
||||
@@ -140,8 +141,8 @@ func TestTransportParsing(t *testing.T) {
|
||||
|
||||
// test invalid
|
||||
|
||||
assert.NotEqual(t, parseTError("spn"), nil, "should fail")
|
||||
assert.NotEqual(t, parseTError("spn:"), nil, "should fail")
|
||||
assert.NotEqual(t, parseTError("spn:0"), nil, "should fail")
|
||||
assert.NotEqual(t, parseTError("spn:65536"), nil, "should fail")
|
||||
require.Error(t, parseTError("spn"), "should fail")
|
||||
require.Error(t, parseTError("spn:"), "should fail")
|
||||
require.Error(t, parseTError("spn:0"), "should fail")
|
||||
require.Error(t, parseTError("spn:65536"), "should fail")
|
||||
}
|
||||
|
||||
@@ -210,9 +210,9 @@ func (m *Map) optimizeForSatelliteConnectivity(result *OptimizationResult) {
|
||||
|
||||
// Add to suggested pins.
|
||||
if len(region.regardedPins) <= region.satelliteMinLanes {
|
||||
result.addSuggested(fmt.Sprintf("best to region %s", region.ID), region.regardedPins...)
|
||||
result.addSuggested("best to region "+region.ID, region.regardedPins...)
|
||||
} else {
|
||||
result.addSuggested(fmt.Sprintf("best to region %s", region.ID), region.regardedPins[:region.satelliteMinLanes]...)
|
||||
result.addSuggested("best to region "+region.ID, region.regardedPins[:region.satelliteMinLanes]...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -622,7 +622,7 @@ func (m *Map) updateQuickSettingExcludeCountryList(ctx context.Context, configKe
|
||||
for _, country := range countryList {
|
||||
quickSettings = append(quickSettings, config.QuickSetting{
|
||||
Name: fmt.Sprintf("Exclude %s (%s)", country.Name, country.Code),
|
||||
Value: []string{fmt.Sprintf("- %s", country.Code)},
|
||||
Value: []string{"- " + country.Code},
|
||||
Action: config.QuickMergeTop,
|
||||
})
|
||||
}
|
||||
@@ -700,7 +700,7 @@ func (m *Map) updateSelectRuleCountryList(ctx context.Context, configKey string,
|
||||
selections = append(selections, selectCountry{
|
||||
QuickSetting: config.QuickSetting{
|
||||
Name: fmt.Sprintf("%s (%s)", country.Name, country.Code),
|
||||
Value: []string{fmt.Sprintf("+ %s", country.Code), "- *"},
|
||||
Value: []string{"+ " + country.Code, "- *"},
|
||||
Action: config.QuickReplace,
|
||||
},
|
||||
FlagID: country.Code,
|
||||
@@ -712,7 +712,7 @@ func (m *Map) updateSelectRuleCountryList(ctx context.Context, configKey string,
|
||||
selections = append(selections, selectCountry{
|
||||
QuickSetting: config.QuickSetting{
|
||||
Name: fmt.Sprintf("%s (C:%s)", continent.Name, continent.Code),
|
||||
Value: []string{fmt.Sprintf("+ C:%s", continent.Code), "- *"},
|
||||
Value: []string{"+ C:" + continent.Code, "- *"},
|
||||
Action: config.QuickReplace,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSharedHTTP(t *testing.T) { //nolint:paralleltest // Test checks global state.
|
||||
@@ -11,23 +12,23 @@ func TestSharedHTTP(t *testing.T) { //nolint:paralleltest // Test checks global
|
||||
|
||||
// Register multiple handlers.
|
||||
err := addHTTPHandler(testPort, "", ServeInfoPage)
|
||||
assert.NoError(t, err, "should be able to share http listener")
|
||||
require.NoError(t, err, "should be able to share http listener")
|
||||
err = addHTTPHandler(testPort, "/test", ServeInfoPage)
|
||||
assert.NoError(t, err, "should be able to share http listener")
|
||||
require.NoError(t, err, "should be able to share http listener")
|
||||
err = addHTTPHandler(testPort, "/test2", ServeInfoPage)
|
||||
assert.NoError(t, err, "should be able to share http listener")
|
||||
require.NoError(t, err, "should be able to share http listener")
|
||||
err = addHTTPHandler(testPort, "/", ServeInfoPage)
|
||||
assert.Error(t, err, "should fail to register path twice")
|
||||
require.Error(t, err, "should fail to register path twice")
|
||||
|
||||
// Unregister
|
||||
assert.NoError(t, removeHTTPHandler(testPort, ""))
|
||||
assert.NoError(t, removeHTTPHandler(testPort, "/test"))
|
||||
assert.NoError(t, removeHTTPHandler(testPort, "/not-registered")) // removing unregistered handler does not error
|
||||
assert.NoError(t, removeHTTPHandler(testPort, "/test2"))
|
||||
assert.NoError(t, removeHTTPHandler(testPort, "/not-registered")) // removing unregistered handler does not error
|
||||
require.NoError(t, removeHTTPHandler(testPort, ""))
|
||||
require.NoError(t, removeHTTPHandler(testPort, "/test"))
|
||||
require.NoError(t, removeHTTPHandler(testPort, "/not-registered")) // removing unregistered handler does not error
|
||||
require.NoError(t, removeHTTPHandler(testPort, "/test2"))
|
||||
require.NoError(t, removeHTTPHandler(testPort, "/not-registered")) // removing unregistered handler does not error
|
||||
|
||||
// Check if all handlers are gone again.
|
||||
sharedHTTPServersLock.Lock()
|
||||
defer sharedHTTPServersLock.Unlock()
|
||||
assert.Equal(t, 0, len(sharedHTTPServers), "shared http handlers should be back to zero")
|
||||
assert.Empty(t, sharedHTTPServers, "shared http handlers should be back to zero")
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ func StartSluice(network, address string) {
|
||||
|
||||
// Start service worker.
|
||||
module.StartServiceWorker(
|
||||
fmt.Sprintf("%s sluice listener", s.network),
|
||||
s.network+" sluice listener",
|
||||
10*time.Second,
|
||||
s.listenHandler,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user