Skip to content

Commit

Permalink
fix ut
Browse files Browse the repository at this point in the history
  • Loading branch information
bartoszWojciechO committed Oct 14, 2024
1 parent 6b199fe commit 3eb12ad
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions daemon/rpc_set_postquantum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package daemon

import (
"context"
"strconv"
"testing"

"github.com/NordSecurity/nordvpn-linux/config"
"github.com/NordSecurity/nordvpn-linux/daemon/events"
"github.com/NordSecurity/nordvpn-linux/daemon/pb"
"github.com/NordSecurity/nordvpn-linux/internal"
"github.com/NordSecurity/nordvpn-linux/test/mock/networker"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -35,14 +37,22 @@ func TestSetPostquantumVpn(t *testing.T) {

mockPublisherSubscriber := events.MockPublisherSubscriber[bool]{}
mockEvents := events.Events{Settings: &events.SettingsEvents{PostquantumVPN: &mockPublisherSubscriber}}
mockNetworker := networker.Mock{}

r := RPC{
cm: &mockConfigManager,
events: &mockEvents,
netw: &mockNetworker,
}

successPayload := pb.Payload{
Type: internal.CodeSuccess,
Data: []string{strconv.FormatBool(false)},
}

successWithVPNPayload := pb.Payload{
Type: internal.CodeSuccess,
Data: []string{strconv.FormatBool(true)},
}

conflictMeshPayload := pb.Payload{
Expand All @@ -57,6 +67,7 @@ func TestSetPostquantumVpn(t *testing.T) {
testName string
pq bool
meshnet bool
vpnActive bool
tech config.Technology
payload *pb.Payload
eventPublished bool
Expand All @@ -65,6 +76,7 @@ func TestSetPostquantumVpn(t *testing.T) {
testName: "pq off mesh is off tech unknown",
pq: false,
meshnet: false,
vpnActive: false,
tech: config.Technology_UNKNOWN_TECHNOLOGY,
payload: &conflictTechPayload,
eventPublished: false,
Expand All @@ -73,6 +85,7 @@ func TestSetPostquantumVpn(t *testing.T) {
testName: "pq off mesh is off tech nlx",
pq: false,
meshnet: false,
vpnActive: false,
tech: config.Technology_NORDLYNX,
payload: &successPayload,
eventPublished: true,
Expand All @@ -81,6 +94,7 @@ func TestSetPostquantumVpn(t *testing.T) {
testName: "pq on mesh is off tech unknown",
pq: true,
meshnet: false,
vpnActive: false,
tech: config.Technology_UNKNOWN_TECHNOLOGY,
payload: &conflictTechPayload,
eventPublished: false,
Expand All @@ -89,6 +103,7 @@ func TestSetPostquantumVpn(t *testing.T) {
testName: "pq on mesh is off tech nlx",
pq: true,
meshnet: false,
vpnActive: false,
tech: config.Technology_NORDLYNX,
payload: &successPayload,
eventPublished: true,
Expand All @@ -97,9 +112,19 @@ func TestSetPostquantumVpn(t *testing.T) {
testName: "pq on mesh is on",
pq: true,
meshnet: true,
vpnActive: false,
payload: &conflictMeshPayload,
eventPublished: false,
},
{
testName: "pq off mesh is off tech nlx vpn on",
pq: false,
meshnet: false,
vpnActive: true,
tech: config.Technology_NORDLYNX,
payload: &successWithVPNPayload,
eventPublished: true,
},
}

for _, test := range tests {
Expand All @@ -108,6 +133,9 @@ func TestSetPostquantumVpn(t *testing.T) {
mockConfigManager.c.Technology = test.tech
mockConfigManager.c.AutoConnectData.PostquantumVpn = !test.pq

mockNetworker.ConnectRetries = 0
mockNetworker.VpnActive = test.vpnActive

req := pb.SetGenericRequest{Enabled: test.pq}
resp, err := r.SetPostQuantum(context.Background(), &req)

Expand Down

0 comments on commit 3eb12ad

Please sign in to comment.