This repository has been archived by the owner on Mar 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
orgs_test.go
104 lines (81 loc) · 2.16 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
99
100
101
102
103
104
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) {
server, client := gapiTestTools(200, getOrgsJSON)
defer server.Close()
orgs, err := client.Orgs()
if err != nil {
t.Error(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) {
server, client := gapiTestTools(200, getOrgJSON)
defer server.Close()
org := "Main Org."
resp, err := client.OrgByName(org)
if err != nil {
t.Error(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) {
server, client := gapiTestTools(200, getOrgJSON)
defer server.Close()
org := int64(1)
resp, err := client.Org(org)
if err != nil {
t.Error(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) {
server, client := gapiTestTools(200, createdOrgJSON)
defer server.Close()
resp, err := client.NewOrg("test-org")
if err != nil {
t.Error(err)
}
t.Log(pretty.PrettyFormat(resp))
if resp != 1 {
t.Error("Not correctly parsing returned creation message.")
}
}
func TestUpdateOrg(t *testing.T) {
server, client := gapiTestTools(200, updatedOrgJSON)
defer server.Close()
err := client.UpdateOrg(int64(1), "test-org")
if err != nil {
t.Error(err)
}
}
func TestDeleteOrg(t *testing.T) {
server, client := gapiTestTools(200, deletedOrgJSON)
defer server.Close()
err := client.DeleteOrg(int64(1))
if err != nil {
t.Error(err)
}
}