Skip to content

Commit

Permalink
Add state-backend-test command
Browse files Browse the repository at this point in the history
  • Loading branch information
bartoszWojciechO committed Aug 8, 2024
1 parent 976836d commit 812ece3
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 13 deletions.
14 changes: 7 additions & 7 deletions build/foss/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
meshpb "github.com/NordSecurity/nordvpn-linux/meshnet/pb"
"github.com/NordSecurity/nordvpn-linux/snapconf"
snappb "github.com/NordSecurity/nordvpn-linux/snapconf/pb"
statepb "github.com/NordSecurity/nordvpn-linux/state/pb"

"github.com/fatih/color"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -96,6 +97,9 @@ func NewApp(version, environment, hash, salt string,
cmd.client = pb.NewDaemonClient(conn)
cmd.meshClient = meshpb.NewMeshnetClient(conn)
cmd.fileshareClient = filesharepb.NewFileshareClient(fileshareConn)
if internal.IsDevEnv(environment) {
cmd.stateClient = statepb.NewStateClient(conn)
}
}

cli.AppHelpTemplate = AppHelpTemplate
Expand Down Expand Up @@ -547,6 +551,14 @@ func NewApp(version, environment, hash, salt string,
},
}

if internal.IsDevEnv(environment) {
app.Commands = append(app.Commands, &cli.Command{
Name: "state-backend-test",
Action: cmd.SubscribeToStatus,
Hidden: true,
})
}

app.Commands = append(app.Commands, meshnetCommand(cmd))

if pingErr == nil {
Expand Down Expand Up @@ -928,6 +940,7 @@ type cmd struct {
client pb.DaemonClient
meshClient meshpb.MeshnetClient
fileshareClient filesharepb.FileshareClient
stateClient statepb.StateClient
environment internal.Environment
loaderInterceptor *LoaderInterceptor
}
Expand Down
2 changes: 1 addition & 1 deletion cli/cli_cities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func TestCitiesList(t *testing.T) {
category.Set(t, category.Unit)
mockClient := mockDaemonClient{}
c := cmd{&mockClient, nil, nil, "", nil}
c := cmd{&mockClient, nil, nil, nil, "", nil}

tests := []struct {
name string
Expand Down
2 changes: 1 addition & 1 deletion cli/cli_connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (c mockDaemonClient) Groups(ctx context.Context, in *pb.Empty, opts ...grpc
func TestConnectAutoComplete(t *testing.T) {
category.Set(t, category.Unit)
mockClient := mockDaemonClient{}
c := cmd{&mockClient, nil, nil, "", nil}
c := cmd{&mockClient, nil, nil, nil, "", nil}
tests := []struct {
name string
countries []*pb.ServerGroup
Expand Down
2 changes: 1 addition & 1 deletion cli/cli_countries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func TestCountriesList(t *testing.T) {
category.Set(t, category.Unit)
mockClient := mockDaemonClient{}
c := cmd{&mockClient, nil, nil, "", nil}
c := cmd{&mockClient, nil, nil, nil, "", nil}

tests := []struct {
name string
Expand Down
2 changes: 1 addition & 1 deletion cli/cli_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func TestGroupsList(t *testing.T) {
category.Set(t, category.Unit)
mockClient := mockDaemonClient{}
c := cmd{&mockClient, nil, nil, "", nil}
c := cmd{&mockClient, nil, nil, nil, "", nil}

tests := []struct {
name string
Expand Down
28 changes: 28 additions & 0 deletions cli/cli_gui_backend.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cli

import (
"context"
"fmt"

"github.com/NordSecurity/nordvpn-linux/state/pb"
"github.com/urfave/cli/v2"
)

// FileshareSend rpc
func (c *cmd) SubscribeToStatus(ctx *cli.Context) error {
fmt.Println("Subscribing to bakckend state.")
srv, err := c.stateClient.Subscribe(context.Background(), &pb.Empty{})
if err != nil {
fmt.Println("Failed to subscribe to state changes: ", err)
}

fmt.Println("Subscribed to bakckend state.")
for {
stateUpdate, err := srv.Recv()
if err != nil {
fmt.Println("Failed to receive state update: ", err)
} else {
fmt.Printf("State update: %+v\n", stateUpdate)
}
}
}
2 changes: 1 addition & 1 deletion cli/cli_mesh_peers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (m mockMeshClient) GetPeers(ctx context.Context, in *pb.Empty, opts ...grpc

func TestMeshPeerList(t *testing.T) {
category.Set(t, category.Unit)
c := cmd{nil, mockMeshClient{}, nil, "", nil}
c := cmd{nil, mockMeshClient{}, nil, nil, "", nil}
tests := []struct {
name string
expected []string
Expand Down
2 changes: 1 addition & 1 deletion cli/cli_set_autoconnect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func TestAutoConnectAutoComplete(t *testing.T) {
category.Set(t, category.Unit)
mockClient := mockDaemonClient{}
c := cmd{&mockClient, nil, nil, "", nil}
c := cmd{&mockClient, nil, nil, nil, "", nil}
tests := []struct {
name string
countries []*pb.ServerGroup
Expand Down

0 comments on commit 812ece3

Please sign in to comment.