This repository has been archived by the owner on Jan 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
/
orgs_test.go
98 lines (75 loc) · 2 KB
/
orgs_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
package gapi
import (
"testing"
"github.com/gobs/pretty"
)
const (
getOrgsJSON = `[{"id":1,"name":"Main Org."},{"id":2,"name":"Test Org."}]`
getOrgJSON = `{"id":1,"name":"Main Org.","address":{"address1":"","address2":"","city":"","zipCode":"","state":"","country":""}}`
createdOrgJSON = `{"message":"Organization created","orgId":1}`
updatedOrgJSON = `{"message":"Organization updated"}`
deletedOrgJSON = `{"message":"Organization deleted"}`
)
func TestOrgs(t *testing.T) {
client := gapiTestTools(t, 200, getOrgsJSON)
orgs, err := client.Orgs()
if err != nil {
t.Fatal(err)
}
t.Log(pretty.PrettyFormat(orgs))
if len(orgs) != 2 {
t.Error("Length of returned orgs should be 2")
}
if orgs[0].ID != 1 || orgs[0].Name != "Main Org." {
t.Error("Not correctly parsing returned organizations.")
}
}
func TestOrgByName(t *testing.T) {
client := gapiTestTools(t, 200, getOrgJSON)
org := "Main Org."
resp, err := client.OrgByName(org)
if err != nil {
t.Fatal(err)
}
t.Log(pretty.PrettyFormat(resp))
if resp.ID != 1 || resp.Name != org {
t.Error("Not correctly parsing returned organization.")
}
}
func TestOrg(t *testing.T) {
client := gapiTestTools(t, 200, getOrgJSON)
org := int64(1)
resp, err := client.Org(org)
if err != nil {
t.Fatal(err)
}
t.Log(pretty.PrettyFormat(resp))
if resp.ID != org || resp.Name != "Main Org." {
t.Error("Not correctly parsing returned organization.")
}
}
func TestNewOrg(t *testing.T) {
client := gapiTestTools(t, 200, createdOrgJSON)
resp, err := client.NewOrg("test-org")
if err != nil {
t.Fatal(err)
}
t.Log(pretty.PrettyFormat(resp))
if resp != 1 {
t.Error("Not correctly parsing returned creation message.")
}
}
func TestUpdateOrg(t *testing.T) {
client := gapiTestTools(t, 200, updatedOrgJSON)
err := client.UpdateOrg(int64(1), "test-org")
if err != nil {
t.Error(err)
}
}
func TestDeleteOrg(t *testing.T) {
client := gapiTestTools(t, 200, deletedOrgJSON)
err := client.DeleteOrg(int64(1))
if err != nil {
t.Error(err)
}
}