Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linter warnings in tests #69

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions internal/addrmon/addrmon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ func TestAddrMonStartStop(t *testing.T) {
// test RegisterAddrUpdates without netlink error
addrMon := NewAddrMon()

netlinkAddrSubscribeWithOptions = func(ch chan<- netlink.AddrUpdate,
done <-chan struct{}, options netlink.AddrSubscribeOptions) error {
netlinkAddrSubscribeWithOptions = func(chan<- netlink.AddrUpdate,
<-chan struct{}, netlink.AddrSubscribeOptions) error {
return nil
}

Expand All @@ -32,7 +32,7 @@ func TestAddrMonStartStop(t *testing.T) {
// test without AddrUpdates
addrMon = NewAddrMon()

RegisterAddrUpdates = func(a *AddrMon) (chan netlink.AddrUpdate, error) {
RegisterAddrUpdates = func(*AddrMon) (chan netlink.AddrUpdate, error) {
return nil, nil
}

Expand Down
8 changes: 4 additions & 4 deletions internal/cpd/cpd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func TestCPDProbeCheck(t *testing.T) {
// probe with status code 400 (-> detected) and early stop
t.Run("stop during probe", func(_ *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusBadRequest)
}))
defer ts.Close()
Expand All @@ -25,7 +25,7 @@ func TestCPDProbeCheck(t *testing.T) {

// check with redirect and no url
t.Run("redirect without url", func(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusFound)
}))
defer ts.Close()
Expand Down Expand Up @@ -53,7 +53,7 @@ func TestCPDProbeCheck(t *testing.T) {

// check with invalid content length
t.Run("invalid content length", func(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Length", "100")
w.WriteHeader(http.StatusOK)
}))
Expand Down Expand Up @@ -167,7 +167,7 @@ func TestCPDHosts(t *testing.T) {
func TestCPDProbe(t *testing.T) {
// status code 204, not detected
t.Run("not detected", func(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusNoContent)
}))
defer ts.Close()
Expand Down
20 changes: 10 additions & 10 deletions internal/dbusapi/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,13 @@ func TestServiceStartStop(t *testing.T) {
}()

// no errors
dbusConnectSystemBus = func(opts ...dbus.ConnOption) (dbusConn, error) {
dbusConnectSystemBus = func(...dbus.ConnOption) (dbusConn, error) {
return &testConn{
reqNameReply: dbus.RequestNameReplyPrimaryOwner,
exportOKNum: 2,
}, nil
}
propExport = func(conn dbusConn, path dbus.ObjectPath, props prop.Map) (propProperties, error) {
propExport = func(dbusConn, dbus.ObjectPath, prop.Map) (propProperties, error) {
return &testProperties{}, nil
}
s := NewService()
Expand All @@ -237,7 +237,7 @@ func TestServiceStartStop(t *testing.T) {
s.Stop()

// conn export introspectable error
dbusConnectSystemBus = func(opts ...dbus.ConnOption) (dbusConn, error) {
dbusConnectSystemBus = func(...dbus.ConnOption) (dbusConn, error) {
return &testConn{
reqNameReply: dbus.RequestNameReplyPrimaryOwner,
exportOKNum: 1,
Expand All @@ -250,7 +250,7 @@ func TestServiceStartStop(t *testing.T) {
}

// props export error
propExport = func(conn dbusConn, path dbus.ObjectPath, props prop.Map) (propProperties, error) {
propExport = func(dbusConn, dbus.ObjectPath, prop.Map) (propProperties, error) {
return nil, errors.New("test error")
}
s = NewService()
Expand All @@ -259,7 +259,7 @@ func TestServiceStartStop(t *testing.T) {
}

// conn export methods error
dbusConnectSystemBus = func(opts ...dbus.ConnOption) (dbusConn, error) {
dbusConnectSystemBus = func(...dbus.ConnOption) (dbusConn, error) {
return &testConn{
reqNameReply: dbus.RequestNameReplyPrimaryOwner,
exportError: errors.New("test error"),
Expand All @@ -271,7 +271,7 @@ func TestServiceStartStop(t *testing.T) {
}

// bus name alredy taken
dbusConnectSystemBus = func(opts ...dbus.ConnOption) (dbusConn, error) {
dbusConnectSystemBus = func(...dbus.ConnOption) (dbusConn, error) {
return &testConn{
reqNameReply: dbus.RequestNameReplyExists,
}, nil
Expand All @@ -282,7 +282,7 @@ func TestServiceStartStop(t *testing.T) {
}

// conn request name error
dbusConnectSystemBus = func(opts ...dbus.ConnOption) (dbusConn, error) {
dbusConnectSystemBus = func(...dbus.ConnOption) (dbusConn, error) {
return &testConn{
reqNameError: errors.New("test error"),
}, nil
Expand All @@ -293,7 +293,7 @@ func TestServiceStartStop(t *testing.T) {
}

// dbus connect error
dbusConnectSystemBus = func(opts ...dbus.ConnOption) (dbusConn, error) {
dbusConnectSystemBus = func(...dbus.ConnOption) (dbusConn, error) {
return nil, errors.New("test error")
}
s = NewService()
Expand Down Expand Up @@ -322,14 +322,14 @@ func TestServiceSetProperty(t *testing.T) {
propExport = oldPropExport
}()

dbusConnectSystemBus = func(opts ...dbus.ConnOption) (dbusConn, error) {
dbusConnectSystemBus = func(...dbus.ConnOption) (dbusConn, error) {
return &testConn{
reqNameReply: dbus.RequestNameReplyPrimaryOwner,
exportOKNum: 2,
}, nil
}
properties := &testProperties{props: make(map[string]any)}
propExport = func(conn dbusConn, path dbus.ObjectPath, props prop.Map) (propProperties, error) {
propExport = func(dbusConn, dbus.ObjectPath, prop.Map) (propProperties, error) {
return properties, nil
}
s := NewService()
Expand Down
6 changes: 3 additions & 3 deletions internal/devmon/devmon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// TestDevMonStartStop tests Start and Stop of DevMon.
func TestDevMonStartStop(t *testing.T) {
// test without LinkUpdates
RegisterLinkUpdates = func(d *DevMon) (chan netlink.LinkUpdate, error) {
RegisterLinkUpdates = func(*DevMon) (chan netlink.LinkUpdate, error) {
return nil, nil
}

Expand Down Expand Up @@ -84,7 +84,7 @@ func TestDevMonStartStop(t *testing.T) {
// send test update in goroutine spawned in RegisterLinkUpdates
// and signal sending complete
sendDone := make(chan struct{})
RegisterLinkUpdates = func(d *DevMon) (chan netlink.LinkUpdate, error) {
RegisterLinkUpdates = func(*DevMon) (chan netlink.LinkUpdate, error) {
updates := make(chan netlink.LinkUpdate)
go func(up netlink.LinkUpdate) {
defer close(sendDone)
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestDevMonStartStop(t *testing.T) {

// test with unexpected close and LinkUpdates
runOnce := false
RegisterLinkUpdates = func(d *DevMon) (chan netlink.LinkUpdate, error) {
RegisterLinkUpdates = func(*DevMon) (chan netlink.LinkUpdate, error) {
updates := make(chan netlink.LinkUpdate)
if !runOnce {
// on first run, close updates
Expand Down
20 changes: 10 additions & 10 deletions internal/execs/execs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestRunIP(t *testing.T) {
got := []string{}

oldRunCmd := RunCmd
RunCmd = func(ctx context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
RunCmd = func(_ context.Context, cmd string, _ string, arg ...string) ([]byte, []byte, error) {
got = append(got, cmd+" "+strings.Join(arg, " "))
return nil, nil, nil
}
Expand All @@ -65,7 +65,7 @@ func TestRunIPLink(t *testing.T) {
got := []string{}

oldRunCmd := RunCmd
RunCmd = func(ctx context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
RunCmd = func(_ context.Context, cmd string, _ string, arg ...string) ([]byte, []byte, error) {
got = append(got, cmd+" "+strings.Join(arg, " "))
return nil, nil, nil
}
Expand All @@ -83,7 +83,7 @@ func TestRunIPAddress(t *testing.T) {
got := []string{}

oldRunCmd := RunCmd
RunCmd = func(ctx context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
RunCmd = func(_ context.Context, cmd string, _ string, arg ...string) ([]byte, []byte, error) {
got = append(got, cmd+" "+strings.Join(arg, " "))
return nil, nil, nil
}
Expand All @@ -101,7 +101,7 @@ func TestRunIP4Route(t *testing.T) {
got := []string{}

oldRunCmd := RunCmd
RunCmd = func(ctx context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
RunCmd = func(_ context.Context, cmd string, _ string, arg ...string) ([]byte, []byte, error) {
got = append(got, cmd+" "+strings.Join(arg, " "))
return nil, nil, nil
}
Expand All @@ -119,7 +119,7 @@ func TestRunIP6Route(t *testing.T) {
got := []string{}

oldRunCmd := RunCmd
RunCmd = func(ctx context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
RunCmd = func(_ context.Context, cmd string, _ string, arg ...string) ([]byte, []byte, error) {
got = append(got, cmd+" "+strings.Join(arg, " "))
return nil, nil, nil
}
Expand All @@ -137,7 +137,7 @@ func TestRunIP4Rule(t *testing.T) {
got := []string{}

oldRunCmd := RunCmd
RunCmd = func(ctx context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
RunCmd = func(_ context.Context, cmd string, _ string, arg ...string) ([]byte, []byte, error) {
got = append(got, cmd+" "+strings.Join(arg, " "))
return nil, nil, nil
}
Expand All @@ -155,7 +155,7 @@ func TestRunIP6Rule(t *testing.T) {
got := []string{}

oldRunCmd := RunCmd
RunCmd = func(ctx context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
RunCmd = func(_ context.Context, cmd string, _ string, arg ...string) ([]byte, []byte, error) {
got = append(got, cmd+" "+strings.Join(arg, " "))
return nil, nil, nil
}
Expand All @@ -173,7 +173,7 @@ func TestRunSysctl(t *testing.T) {
got := []string{}

oldRunCmd := RunCmd
RunCmd = func(ctx context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
RunCmd = func(_ context.Context, cmd string, _ string, arg ...string) ([]byte, []byte, error) {
got = append(got, cmd+" "+strings.Join(arg, " "))
return nil, nil, nil
}
Expand All @@ -191,7 +191,7 @@ func TestRunNft(t *testing.T) {
got := []string{}

oldRunCmd := RunCmd
RunCmd = func(ctx context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
RunCmd = func(_ context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
got = append(got, cmd+" "+strings.Join(arg, " ")+" "+s)
return nil, nil, nil
}
Expand All @@ -209,7 +209,7 @@ func TestRunResolvectl(t *testing.T) {
got := []string{}

oldRunCmd := RunCmd
RunCmd = func(ctx context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
RunCmd = func(_ context.Context, cmd string, _ string, arg ...string) ([]byte, []byte, error) {
got = append(got, cmd+" "+strings.Join(arg, " "))
return []byte("OK"), nil, nil
}
Expand Down
4 changes: 2 additions & 2 deletions internal/sleepmon/sleepmon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestSleepMonStartEvents(t *testing.T) {
func TestSleepMonStartErrors(t *testing.T) {
// match signal error
oldAddMatchSignal := connAddMatchSignal
connAddMatchSignal = func(conn *dbus.Conn, options ...dbus.MatchOption) error {
connAddMatchSignal = func(*dbus.Conn, ...dbus.MatchOption) error {
return errors.New("test error")
}
defer func() { connAddMatchSignal = oldAddMatchSignal }()
Expand All @@ -74,7 +74,7 @@ func TestSleepMonStartErrors(t *testing.T) {
}

// system bus error
dbusConnectSystemBus = func(opts ...dbus.ConnOption) (*dbus.Conn, error) {
dbusConnectSystemBus = func(...dbus.ConnOption) (*dbus.Conn, error) {
return nil, errors.New("test error")
}
defer func() { dbusConnectSystemBus = dbus.ConnectSystemBus }()
Expand Down
10 changes: 5 additions & 5 deletions internal/splitrt/excludes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestExcludesAddStatic(t *testing.T) {

// set testing runNft function
got := []string{}
execs.RunCmd = func(ctx context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
execs.RunCmd = func(_ context.Context, _ string, s string, _ ...string) ([]byte, []byte, error) {
got = append(got, s)
return nil, nil, nil
}
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestExcludesAddDynamic(t *testing.T) {

// set testing runNft function
got := []string{}
execs.RunCmd = func(ctx context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
execs.RunCmd = func(_ context.Context, _ string, s string, _ ...string) ([]byte, []byte, error) {
got = append(got, s)
return nil, nil, nil
}
Expand Down Expand Up @@ -177,7 +177,7 @@ func TestExcludesRemove(t *testing.T) {
// set testing runNft function
got := []string{}
oldRunCmd := execs.RunCmd
execs.RunCmd = func(ctx context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
execs.RunCmd = func(_ context.Context, _ string, s string, _ ...string) ([]byte, []byte, error) {
got = append(got, s)
return nil, nil, nil
}
Expand Down Expand Up @@ -220,7 +220,7 @@ func TestExcludesRemove(t *testing.T) {

// test with nft error
got = []string{}
execs.RunCmd = func(ctx context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
execs.RunCmd = func(_ context.Context, _ string, s string, _ ...string) ([]byte, []byte, error) {
got = append(got, s)
return nil, nil, errors.New("test error")
}
Expand Down Expand Up @@ -269,7 +269,7 @@ func TestExcludesCleanup(t *testing.T) {

// set testing runNft function
got := []string{}
execs.RunCmd = func(ctx context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
execs.RunCmd = func(_ context.Context, _ string, s string, _ ...string) ([]byte, []byte, error) {
got = append(got, s)
return nil, nil, nil
}
Expand Down
12 changes: 6 additions & 6 deletions internal/splitrt/splitrt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestSplitRoutingHandleDeviceUpdate(t *testing.T) {
got := []string{"nothing else"}

oldRunCmd := execs.RunCmd
execs.RunCmd = func(ctx context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
execs.RunCmd = func(_ context.Context, _ string, s string, _ ...string) ([]byte, []byte, error) {
got = append(got, s)
return nil, nil, nil
}
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestSplitRoutingHandleAddressUpdate(t *testing.T) {

got := []string{}
oldRunCmd := execs.RunCmd
execs.RunCmd = func(ctx context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
execs.RunCmd = func(_ context.Context, _ string, s string, _ ...string) ([]byte, []byte, error) {
got = append(got, s)
return nil, nil, nil
}
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestSplitRoutingHandleDNSReport(t *testing.T) {

got := []string{}
oldRunCmd := execs.RunCmd
execs.RunCmd = func(ctx context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
execs.RunCmd = func(_ context.Context, _ string, s string, _ ...string) ([]byte, []byte, error) {
got = append(got, s)
return nil, nil, nil
}
Expand Down Expand Up @@ -188,7 +188,7 @@ func TestSplitRoutingHandleDNSReport(t *testing.T) {
func TestSplitRoutingStartStop(t *testing.T) {
// set dummy low level functions for testing
oldRunCmd := execs.RunCmd
execs.RunCmd = func(ctx context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
execs.RunCmd = func(context.Context, string, string, ...string) ([]byte, []byte, error) {
return nil, nil, nil
}
defer func() { execs.RunCmd = oldRunCmd }()
Expand Down Expand Up @@ -263,7 +263,7 @@ func TestSplitRoutingStartStop(t *testing.T) {
s.Stop()

// test with nft errors
execs.RunCmd = func(ctx context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
execs.RunCmd = func(context.Context, string, string, ...string) ([]byte, []byte, error) {
return nil, nil, errors.New("test error")
}
s = NewSplitRouting(NewConfig(), vpnconfig.New())
Expand Down Expand Up @@ -312,7 +312,7 @@ func TestCleanup(t *testing.T) {
got := []string{}

oldRunCmd := execs.RunCmd
execs.RunCmd = func(ctx context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
execs.RunCmd = func(_ context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
if s == "" {
got = append(got, cmd+" "+strings.Join(arg, " "))
return nil, nil, nil
Expand Down
4 changes: 2 additions & 2 deletions internal/trafpol/allowdevs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestAllowDevsAdd(t *testing.T) {
ctx := context.Background()

got := []string{}
execs.RunCmd = func(ctx context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
execs.RunCmd = func(_ context.Context, _ string, s string, _ ...string) ([]byte, []byte, error) {
got = append(got, s)
return nil, nil, nil
}
Expand Down Expand Up @@ -42,7 +42,7 @@ func TestAllowDevsRemove(t *testing.T) {
ctx := context.Background()

got := []string{}
execs.RunCmd = func(ctx context.Context, cmd string, s string, arg ...string) ([]byte, []byte, error) {
execs.RunCmd = func(_ context.Context, _ string, s string, _ ...string) ([]byte, []byte, error) {
got = append(got, s)
return nil, nil, nil
}
Expand Down
Loading
Loading