-
Notifications
You must be signed in to change notification settings - Fork 0
/
organizations_test.go
executable file
·214 lines (202 loc) · 5.3 KB
/
organizations_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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
package turso
import (
"os"
"testing"
)
var org_name string = os.Getenv("TURSO_ORG_NAME")
var db_name string = os.Getenv("TURSO_DB_NAME")
var instance_name string = os.Getenv("TURSO_INSTANCE_NAME")
func TestOrganizationList(t *testing.T) {
client, err := newClient()
if err != nil || client == nil {
t.Error(err)
}
orgs, err := client.Organizations.List()
if err != nil {
t.Error(err)
}
if orgs == nil && len(orgs.Orgs) == 0 {
t.Error("organizations should not be nil")
}
}
func TestOrganizationMembers(t *testing.T) {
client, err := newClient()
if err != nil || client == nil {
t.Error(err)
}
members, err := client.Organizations.Members(org_name)
if err != nil {
t.Error(err)
}
if members == nil && len(members.Members) == 0 {
t.Error("members should not be nil")
}
members, err = client.Organizations.Members("")
if err.Error() != "organization slug is required" {
t.Error(err)
}
}
func TestOrganizationDatabases(t *testing.T) {
client, err := newClient()
if err != nil || client == nil {
t.Error(err)
}
databases, err := client.Organizations.Databases(org_name)
if err != nil {
t.Error(err)
}
if databases == nil && len(databases.Databases) == 0 {
t.Error("databases should not be nil")
}
databases, err = client.Organizations.Databases("")
if err.Error() != "organization slug is required" {
t.Error(err)
}
}
func TestOrganizationDatabase(t *testing.T) {
client, err := newClient()
if err != nil || client == nil {
t.Error(err)
}
database, err := client.Organizations.Database(org_name, db_name)
if err != nil {
t.Error(err)
}
if database == nil && database.Database.Name != db_name {
t.Error("databases should not be nil")
}
database, err = client.Organizations.Database("", db_name)
if err.Error() != "organization slug is required" {
t.Error(err)
}
database, err = client.Organizations.Database(org_name, "")
if err.Error() != "database name is required" {
t.Error(err)
}
}
func TestOrganizationInstances(t *testing.T) {
client, err := newClient()
if err != nil || client == nil {
t.Error(err)
}
instances, err := client.Organizations.Instances(org_name, db_name)
if err != nil {
t.Error(err)
}
if instances == nil && len(instances.Instances) == 0 {
t.Error("instaces should not be nil")
}
instances, err = client.Organizations.Instances("", db_name)
if err.Error() != "organization slug is required" {
t.Error(err)
}
instances, err = client.Organizations.Instances(org_name, "")
if err.Error() != "database name is required" {
t.Error(err)
}
}
func TestOrganizationInstance(t *testing.T) {
client, err := newClient()
if err != nil || client == nil {
t.Error(err)
}
instances, err := client.Organizations.Instance(org_name, db_name, instance_name)
if err != nil {
t.Error(err)
}
if instances == nil && instances.Instance.Name != instance_name {
t.Error("instances should not be nil")
}
instances, err = client.Organizations.Instance("", db_name, instance_name)
if err.Error() != "organization slug is required" {
t.Error(err)
}
instances, err = client.Organizations.Instance(org_name, "", instance_name)
if err.Error() != "database name is required" {
t.Error(err)
}
instances, err = client.Organizations.Instance(org_name, db_name, "")
if err.Error() != "instance name is required" {
t.Error(err)
}
}
func TestOrganizationDBUsage(t *testing.T) {
client, err := newClient()
if err != nil || client == nil {
t.Error(err)
}
usage, err := client.Organizations.DBUsage(org_name, db_name)
if err != nil {
t.Error(err)
}
if usage == nil {
t.Error("instaces should not be nil")
}
if usage.Database.UUID == "" {
t.Error("uuid should not be empty")
}
usage, err = client.Organizations.DBUsage("", db_name)
if err.Error() != "organization slug is required" {
t.Error(err)
}
usage, err = client.Organizations.DBUsage(org_name, "")
if err.Error() != "database name is required" {
t.Error(err)
}
}
func TestOrganizationInvitesList(t *testing.T) {
client, err := newClient()
if err != nil || client == nil {
t.Error(err)
}
invites, err := client.Organizations.ListInvites(org_name)
if err != nil {
t.Error(err)
}
if invites == nil && len(invites.Invites) == 0 {
t.Error("invites should not be nil")
}
invites, err = client.Organizations.ListInvites("")
if err.Error() != "organization slug is required" {
t.Error(err)
}
}
func TestOrganizationGroups(t *testing.T) {
client, err := newClient()
if err != nil || client == nil {
t.Error(err)
}
groups, err := client.Organizations.ListGroups(org_name)
if err != nil {
t.Error(err)
}
if groups == nil && len(groups.Groups) == 0 {
t.Error("groups should not be nil")
}
groups, err = client.Organizations.ListGroups("")
if err.Error() != "organization slug is required" {
t.Error(err)
}
}
func TestOrganizationGroup(t *testing.T) {
client, err := newClient()
if err != nil || client == nil {
t.Error(err)
}
group_name := "default"
groups, err := client.Organizations.Group(org_name, group_name)
if err != nil {
t.Error(err)
}
if groups == nil && groups.Group.Name != group_name {
t.Error("groups should not be nil")
}
groups, err = client.Organizations.Group("", group_name)
if err.Error() != "organization slug is required" {
t.Error(err)
}
groups, err = client.Organizations.Group(org_name, "")
if err.Error() != "group name is required" {
t.Error(err)
}
}