-
Notifications
You must be signed in to change notification settings - Fork 6
/
connection_test.go
140 lines (109 loc) · 3.78 KB
/
connection_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
//go:build all || unittests || specific
// +build all unittests specific
package guacamole
import (
"fmt"
"os"
"strings"
"testing"
"github.com/techBeck03/guacamole-api-client/types"
)
var (
connectionsConfig = 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,
}
testConnection = types.GuacConnection{
Name: "Test Connection",
Protocol: "ssh",
ParentIdentifier: "1592",
Path: fmt.Sprintf("%s/Test Connection", os.Getenv("GUACAMOLE_CONNECTION_PATH")),
}
)
func TestListConnections(t *testing.T) {
if os.Getenv("GUACAMOLE_COOKIES") != "" {
connectionsConfig.Cookies = make(map[string]string)
for _, e := range strings.Split(os.Getenv("GUACAMOLE_COOKIES"), ",") {
cookie_split := strings.Split(e, "=")
connectionsConfig.Cookies[cookie_split[0]] = cookie_split[1]
}
}
client := New(connectionsConfig)
err := client.Connect()
if err != nil {
t.Errorf("Error %s connecting to guacamole with config %+v", err, connectionsConfig)
}
_, err = client.ListConnections()
if err != nil {
t.Errorf("Error %s listing connections with client %+v", err, client)
}
}
func TestCreateConnection(t *testing.T) {
client := New(connectionsConfig)
err := client.Connect()
if err != nil {
t.Errorf("Error %s connecting to guacamole with config %+v", err, connectionsConfig)
}
err = client.CreateConnection(&testConnection)
if err != nil {
t.Errorf("Error %s creating connection: %s with client %+v", err, testConnection.Name, client)
}
}
func TestReadConnection(t *testing.T) {
client := New(connectionsConfig)
err := client.Connect()
if err != nil {
t.Errorf("Error %s connecting to guacamole with config %+v", err, connectionsConfig)
}
connection, err := client.ReadConnection(testConnection.Identifier)
if err != nil {
t.Errorf("Error %s reading connection: %s with client %+v", err, testConnection.Name, client)
}
if connection.Name != testConnection.Name {
t.Errorf("Expected connection name = %s read connection name = %s", testConnection.Name, connection.Name)
}
}
func TestReadConnectionByPath(t *testing.T) {
client := New(connectionsConfig)
err := client.Connect()
if err != nil {
t.Errorf("Error %s connecting to guacamole with config %+v", err, connectionsConfig)
}
_, err = client.ReadConnectionByPath(fmt.Sprintf("%s", testConnection.Path))
if err != nil {
t.Errorf("Error %s reading connection by path: %s with client %+v", err, testConnection.Path, client)
}
}
func TestUpdateConnection(t *testing.T) {
client := New(connectionsConfig)
err := client.Connect()
if err != nil {
t.Errorf("Error %s connecting to guacamole with config %+v", err, connectionsConfig)
}
connection, err := client.ReadConnection(testConnection.Identifier)
if err != nil {
t.Errorf("Error %s reading connection: %s with client %+v", err, testConnection.Identifier, client)
}
connection.Parameters.Hostname = "testing.example.com"
connection.Parameters.Port = "22"
connection.Attributes.MaxConnections = "2"
err = client.UpdateConnection(&connection)
if err != nil {
t.Errorf("Error %s updating connection: %s with client %+v", err, testConnection.Identifier, client)
}
}
func TestDeleteConnection(t *testing.T) {
client := New(connectionsConfig)
err := client.Connect()
if err != nil {
t.Errorf("Error %s connecting to guacamole with config %+v", err, connectionsConfig)
}
err = client.DeleteConnection(testConnection.Identifier)
if err != nil {
t.Errorf("Error %s deleting connection: %s with client %+v", err, testConnection.Identifier, client)
}
}