summaryrefslogtreecommitdiff
path: root/internal/server/profile_test.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2023-02-16 17:42:49 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2023-02-16 17:42:49 +0100
commit354706c76e0531a282d1ee904ec5a0640ab34627 (patch)
tree8aef16053b303de4b94cbe29134ea9a2ee444ca7 /internal/server/profile_test.go
parent7bd8586b2f9d1cf6aa68c88a1ce943e6e610e2b2 (diff)
Server: Add test for profiles
Diffstat (limited to 'internal/server/profile_test.go')
-rw-r--r--internal/server/profile_test.go100
1 files changed, 100 insertions, 0 deletions
diff --git a/internal/server/profile_test.go b/internal/server/profile_test.go
new file mode 100644
index 0000000..777d51c
--- /dev/null
+++ b/internal/server/profile_test.go
@@ -0,0 +1,100 @@
+package server
+
+import "testing"
+
+func Test_CurrentProfileIndex(t *testing.T) {
+ testCases := []struct {
+ profiles []Profile
+ current string
+ index int
+ }{
+ {
+ profiles: []Profile{
+ {
+ ID: "a",
+ DisplayName: "b",
+ VPNProtoList: []string{"openvpn", "wireguard"},
+ },
+ },
+ current: "a",
+ index: 0,
+ },
+ {
+ profiles: []Profile{
+ {
+ ID: "a",
+ DisplayName: "a",
+ VPNProtoList: []string{"openvpn", "wireguard"},
+ },
+ {
+ ID: "b",
+ DisplayName: "b",
+ VPNProtoList: []string{"openvpn", "wireguard"},
+ },
+ },
+ current: "b",
+ index: 1,
+ },
+ {
+ profiles: []Profile{
+ {
+ ID: "a",
+ DisplayName: "a",
+ VPNProtoList: []string{"openvpn", "wireguard"},
+ },
+ {
+ ID: "b",
+ DisplayName: "b",
+ VPNProtoList: []string{"openvpn", "wireguard"},
+ },
+ },
+ current: "",
+ index: 0,
+ },
+ {
+ profiles: []Profile{
+ {
+ ID: "a",
+ DisplayName: "a",
+ VPNProtoList: []string{"openvpn", "wireguard"},
+ },
+ {
+ ID: "b",
+ DisplayName: "b",
+ VPNProtoList: []string{"openvpn", "wireguard"},
+ },
+ },
+ current: "",
+ index: 0,
+ },
+ {
+ profiles: []Profile{
+ {
+ ID: "a",
+ DisplayName: "a",
+ VPNProtoList: []string{"openvpn", "wireguard"},
+ },
+ {
+ ID: "b",
+ DisplayName: "b",
+ VPNProtoList: []string{"openvpn", "wireguard"},
+ },
+ },
+ current: "idonotexist",
+ index: 0,
+ },
+ }
+
+ for _, tc := range testCases {
+ pri := &ProfileInfo{
+ Current: tc.current,
+ Info: ProfileListInfo{
+ ProfileList: tc.profiles,
+ },
+ }
+ got := pri.CurrentProfileIndex()
+ if got != tc.index {
+ t.Fatalf("failed getting profile index, got: '%v', want: '%v'", got, tc.index)
+ }
+ }
+}