forked from NordSecurity/nordvpn-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Marius Sincovici <[email protected]>
- Loading branch information
1 parent
d933864
commit 8edc1f2
Showing
4 changed files
with
71 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package cli | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/NordSecurity/nordvpn-linux/client/config" | ||
"github.com/NordSecurity/nordvpn-linux/test/category" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func TestGroupsList(t *testing.T) { | ||
category.Set(t, category.Unit) | ||
mockClient := mockDaemonClient{} | ||
c := cmd{&mockClient, nil, nil, "", nil, config.Config{}, nil} | ||
|
||
tests := []struct { | ||
name string | ||
groups []string | ||
expected string | ||
input string | ||
expectedError error | ||
}{ | ||
{ | ||
name: "error response", | ||
expectedError: formatError(fmt.Errorf(MsgListIsEmpty, "server groups")), | ||
}, | ||
{ | ||
name: "groups list", | ||
expected: "group1, group2", | ||
groups: []string{"group1", "group2"}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
app := cli.NewApp() | ||
set := flag.NewFlagSet("test", 0) | ||
mockClient.groups = test.groups | ||
ctx := cli.NewContext(app, set, &cli.Context{Context: context.Background()}) | ||
|
||
result, err := captureOutput(func() { | ||
err := c.Groups(ctx) | ||
assert.Equal(t, test.expectedError, err) | ||
}) | ||
assert.Nil(t, err) | ||
assert.Equal(t, test.expected, result) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters