Skip to content

Commit

Permalink
Increase usage of newMockedServer in meshnet tests
Browse files Browse the repository at this point in the history
Following changes were done:
* Instead of executing NewServer in meshnet tests when only some of
  server fields need to be changed, newMockedServer helper function is
  used instead to reduce code duplication;
* Some dead code removed.

Signed-off-by: Savolro <me@savolro.com>
  • Loading branch information
Savolro committed Feb 25, 2025
1 parent d18e481 commit 373e8e2
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 417 deletions.
1 change: 0 additions & 1 deletion cmd/daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ func main() {
notificationClient,
analytics,
norduserService,
meshAPIex,
statePublisher,
sharedContext,
rcConfig,
Expand Down
36 changes: 0 additions & 36 deletions core/mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,42 +262,6 @@ func peersResponseToLocalPeers(rawPeers []mesh.MachinePeerResponse) []mesh.Machi
return peers
}

// Local peer list.
func (api *DefaultAPI) Local(token string) (mesh.Machines, error) {
api.mu.Lock()
defer api.mu.Unlock()

resp, err := api.request(
urlMeshMachines,
http.MethodGet,
nil,
token,
)
if err != nil {
return nil, err
}
defer resp.Body.Close()

if err := ExtractError(resp); err != nil {
return nil, err
}

body, err := MaxBytesReadAll(resp.Body)
if err != nil {
return nil, err
}

var rawPeers []mesh.MachinePeerResponse
err = json.Unmarshal(body, &rawPeers)
if err != nil {
return nil, err
}

peers := peersResponseToLocalPeers(rawPeers)

return peers, nil
}

func (api *DefaultAPI) Map(token string, self uuid.UUID) (*mesh.MachineMap, error) {
api.mu.Lock()
defer api.mu.Unlock()
Expand Down
2 changes: 0 additions & 2 deletions core/mesh/mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ type Registry interface {
) error
// Unregister Peer from the mesh network.
Unregister(token string, self uuid.UUID) error
// Local peers owned the same user.
Local(token string) (Machines, error)
// List given peer's neighbours in the mesh network.
List(token string, self uuid.UUID) (MachinePeers, error)
Map(token string, self uuid.UUID) (*MachineMap, error)
Expand Down
4 changes: 0 additions & 4 deletions daemon/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ type RegistryMock struct {
listErr error
peers mesh.MachinePeers
configureErr error
localPeers mesh.Machines
}

func (*RegistryMock) Register(token string, self mesh.Machine) (*mesh.Machine, error) {
Expand All @@ -68,9 +67,6 @@ func (r *RegistryMock) Configure(string, uuid.UUID, uuid.UUID, mesh.PeerUpdateRe
}

func (*RegistryMock) Unregister(token string, self uuid.UUID) error { return nil }
func (r *RegistryMock) Local(token string) (mesh.Machines, error) {
return r.localPeers, nil
}

func (r *RegistryMock) List(token string, self uuid.UUID) (mesh.MachinePeers, error) {
if r.listErr != nil {
Expand Down
4 changes: 0 additions & 4 deletions daemon/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/NordSecurity/nordvpn-linux/config"
"github.com/NordSecurity/nordvpn-linux/config/remote"
"github.com/NordSecurity/nordvpn-linux/core"
"github.com/NordSecurity/nordvpn-linux/core/mesh"
"github.com/NordSecurity/nordvpn-linux/daemon/dns"
daemonevents "github.com/NordSecurity/nordvpn-linux/daemon/events"
"github.com/NordSecurity/nordvpn-linux/daemon/pb"
Expand Down Expand Up @@ -52,7 +51,6 @@ type RPC struct {
ncClient nc.NotificationClient
analytics events.Analytics
norduser service.Service
meshRegistry mesh.Registry
systemShutdown atomic.Bool
statePublisher *state.StatePublisher
ConnectionParameters ParametersStorage
Expand Down Expand Up @@ -82,7 +80,6 @@ func NewRPC(
ncClient nc.NotificationClient,
analytics events.Analytics,
norduser service.Service,
meshRegistry mesh.Registry,
statePublisher *state.StatePublisher,
connectContext *sharedctx.Context,
remoteConfigGetter remote.RemoteConfigGetter,
Expand Down Expand Up @@ -110,7 +107,6 @@ func NewRPC(
ncClient: ncClient,
analytics: analytics,
norduser: norduser,
meshRegistry: meshRegistry,
statePublisher: statePublisher,
connectContext: connectContext,
remoteConfigGetter: remoteConfigGetter,
Expand Down
7 changes: 3 additions & 4 deletions daemon/rpc_set_lan_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,9 @@ func TestSetLANDiscovery_Success(t *testing.T) {
}}

rpc := RPC{
cm: configManager,
netw: &networker,
events: &mockEvents,
meshRegistry: &RegistryMock{},
cm: configManager,
netw: &networker,
events: &mockEvents,
}
resp, err := rpc.SetLANDiscovery(context.Background(), &pb.SetLANDiscoveryRequest{
Enabled: test.enabled,
Expand Down
1 change: 0 additions & 1 deletion daemon/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ func testRPC() *RPC {
nil,
&mockAnalytics{},
&testnorduser.MockNorduserCombinedService{},
&RegistryMock{},
nil,
sharedctx.New(),
mock.NewRemoteConfigMock(),
Expand Down
5 changes: 0 additions & 5 deletions meshnet/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ func (r *Registry) Unregister(token string, self uuid.UUID) error {
return r.inner.Unregister(token, self)
}

// Local peers owned the same user.
func (r *Registry) Local(token string) (mesh.Machines, error) {
return r.inner.Local(token)
}

// List given peer's neighbours in the mesh network.
func (r *Registry) List(token string, self uuid.UUID) (resp mesh.MachinePeers, err error) {
anotherMachine := self
Expand Down
Loading

0 comments on commit 373e8e2

Please sign in to comment.