-
Notifications
You must be signed in to change notification settings - Fork 6
/
connection_groups_test.go
141 lines (111 loc) · 4.11 KB
/
connection_groups_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//go:build all || unittests
// +build all unittests
package guacamole
import (
"fmt"
"os"
"strings"
"testing"
"github.com/techBeck03/guacamole-api-client/types"
)
var (
connectionGroupsConfig = Config{
URL: os.Getenv("GUACAMOLE_URL"),
Username: os.Getenv("GUACAMOLE_USERNAME"),
Password: os.Getenv("GUACAMOLE_PASSWORD"),
Token: os.Getenv("GUACAMOLE_TOKEN"),
DataSource: os.Getenv("GUACAMOLE_DATA_SOURCE"),
DisableTLSVerification: true,
}
testConnectionGroup = types.GuacConnectionGroup{
Name: "Testing Group",
Type: "ORGANIZATIONAL",
}
)
func TestListConnectionGroups(t *testing.T) {
if os.Getenv("GUACAMOLE_COOKIES") != "" {
connectionGroupsConfig.Cookies = make(map[string]string)
for _, e := range strings.Split(os.Getenv("GUACAMOLE_COOKIES"), ",") {
cookie_split := strings.Split(e, "=")
connectionGroupsConfig.Cookies[cookie_split[0]] = cookie_split[1]
}
}
client := New(connectionGroupsConfig)
err := client.Connect()
if err != nil {
t.Errorf("Error %s connecting to guacamole with config %+v", err, connectionGroupsConfig)
}
_, err = client.ListConnectionGroups()
if err != nil {
t.Errorf("Error %s listing connection group with client %+v", err, client)
}
}
func TestCreateConnectionGroup(t *testing.T) {
client := New(connectionGroupsConfig)
err := client.Connect()
if err != nil {
t.Errorf("Error %s connecting to guacamole with config %+v", err, connectionGroupsConfig)
}
grp, err := client.ReadConnectionGroupByPath(os.Getenv("GUACAMOLE_CONNECTION_PATH"))
if err != nil {
t.Errorf("Error unable to find parent group with path: %s", os.Getenv("GUACAMOLE_CONNECTION_PATH"))
}
testConnectionGroup.ParentIdentifier = grp.Identifier
testConnectionGroup.Path = fmt.Sprintf("%s/%s", grp.Path, testConnectionGroup.Name)
err = client.CreateConnectionGroup(&testConnectionGroup)
if err != nil {
t.Errorf("Error %s creating connection group: %s with client %+v", err, testConnectionGroup.Name, client)
}
}
func TestReadConnectionGroup(t *testing.T) {
client := New(connectionGroupsConfig)
err := client.Connect()
if err != nil {
t.Errorf("Error %s connecting to guacamole with config %+v", err, connectionGroupsConfig)
}
connectionGroup, err := client.ReadConnectionGroup(testConnectionGroup.Identifier)
if err != nil {
t.Errorf("Error %s reading connection group: %s with client %+v", err, testConnectionGroup.Name, client)
}
if connectionGroup.Name != testConnectionGroup.Name {
t.Errorf("Expected connection name = %s read connection name = %s", testConnectionGroup.Name, connectionGroup.Name)
}
}
func TestReadConnectionGroupByPath(t *testing.T) {
client := New(connectionGroupsConfig)
err := client.Connect()
if err != nil {
t.Errorf("Error %s connecting to guacamole with config %+v", err, connectionGroupsConfig)
}
_, err = client.ReadConnectionGroupByPath(testConnectionGroup.Path)
if err != nil {
t.Errorf("Error %s reading connection by path: %s with client %+v", err, testConnectionGroup.Path, client)
}
}
func TestUpdateConnectionGroup(t *testing.T) {
client := New(connectionGroupsConfig)
err := client.Connect()
if err != nil {
t.Errorf("Error %s connecting to guacamole with config %+v", err, connectionGroupsConfig)
}
connectionGroup, err := client.ReadConnectionGroup(testConnectionGroup.Identifier)
if err != nil {
t.Errorf("Error %s reading connection group: %s with client %+v", err, testConnectionGroup.Identifier, client)
}
connectionGroup.Type = "BALANCING"
err = client.UpdateConnectionGroup(&connectionGroup)
if err != nil {
t.Errorf("Error %s updating connection group: %s with client %+v", err, testConnectionGroup.Identifier, client)
}
}
func TestDeleteConnectionGroup(t *testing.T) {
client := New(connectionGroupsConfig)
err := client.Connect()
if err != nil {
t.Errorf("Error %s connecting to guacamole with config %+v", err, connectionGroupsConfig)
}
err = client.DeleteConnectionGroup(testConnectionGroup.Identifier)
if err != nil {
t.Errorf("Error %s deleting connection group: %s with client %+v", err, testConnectionGroup.Identifier, client)
}
}