-
Notifications
You must be signed in to change notification settings - Fork 53
/
organization_test.go
161 lines (123 loc) · 5.15 KB
/
organization_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
package signalfx
import (
"context"
"net/http"
"net/url"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
"github.com/signalfx/signalfx-go/organization"
)
func TestGetOrganization(t *testing.T) {
teardown := setup()
defer teardown()
mux.HandleFunc("/v2/organization/string", verifyRequest(t, "GET", true, http.StatusOK, nil, "organization/get_success.json"))
result, err := client.GetOrganization(context.Background(), "string")
assert.NoError(t, err, "Unexpected error getting organization")
assert.Equal(t, result.Id, "string", "Id does not match")
}
func TestGetMissingOrganization(t *testing.T) {
teardown := setup()
defer teardown()
mux.HandleFunc("/v2/organization/string", verifyRequest(t, "GET", true, http.StatusNotFound, nil, ""))
result, err := client.GetDetector(context.Background(), "string")
assert.Error(t, err, "Should have gotten an error from a missing organization")
assert.Nil(t, result, "Should have gotten a nil result from a missing organization")
}
func TestGetMember(t *testing.T) {
teardown := setup()
defer teardown()
mux.HandleFunc("/v2/organization/member/string", verifyRequest(t, "GET", true, http.StatusOK, nil, "organization/get_member_success.json"))
result, err := client.GetMember(context.Background(), "string")
assert.NoError(t, err, "Unexpected error getting member")
assert.Equal(t, result.Id, "string", "Id does not match")
}
func TestGetMissingMember(t *testing.T) {
teardown := setup()
defer teardown()
mux.HandleFunc("/v2/organization/member/string", verifyRequest(t, "GET", true, http.StatusNotFound, nil, ""))
result, err := client.GetMember(context.Background(), "string")
assert.Error(t, err, "Should have gotten an error from a missing member")
assert.Nil(t, result, "Should have gotten a nil result from a missing member")
}
func TestInviteMember(t *testing.T) {
teardown := setup()
defer teardown()
mux.HandleFunc("/v2/organization/member", verifyRequest(t, "POST", true, http.StatusOK, nil, "organization/invite_member_success.json"))
results, err := client.InviteMember(context.Background(), &organization.CreateUpdateMemberRequest{
Email: "string",
})
assert.NoError(t, err, "Unexpected error inviting member")
assert.Equal(t, "string", results.Email, "Incorrect email")
}
func TestUpdateMember(t *testing.T) {
teardown := setup()
defer teardown()
mux.HandleFunc("/v2/organization/member/string", verifyRequest(t, "PUT", true, http.StatusOK, nil, "organization/update_member_success.json"))
results, err := client.UpdateMember(context.Background(), "string", &organization.UpdateMemberRequest{
Admin: true,
})
assert.NoError(t, err, "Unexpected error updating member")
assert.Equal(t, true, results.Admin, "Incorrect admin config")
}
func TestGetInviteMembers(t *testing.T) {
teardown := setup()
defer teardown()
mux.HandleFunc("/v2/organization/members", verifyRequest(t, "POST", true, http.StatusOK, nil, "organization/invite_members_success.json"))
members := make([]*organization.Member, 1)
members[0] = &organization.Member{
Email: "string",
}
results, err := client.InviteMembers(context.Background(), &organization.InviteMembersRequest{
Members: members,
})
assert.NoError(t, err, "Unexpected error inviting members")
assert.Equal(t, 1, len(results.Members), "Incorrect email")
}
func TestGetOrganizationMembers(t *testing.T) {
teardown := setup()
defer teardown()
limit := 10
query := "foo"
offset := 2
orderBy := "bar"
params := url.Values{}
params.Add("limit", strconv.Itoa(limit))
params.Add("query", query)
params.Add("offset", strconv.Itoa(offset))
params.Add("orderBy", orderBy)
mux.HandleFunc("/v2/organization/member", verifyRequest(t, "GET", true, http.StatusOK, params, "organization/get_organization_members_success.json"))
results, err := client.GetOrganizationMembers(context.Background(), limit, query, offset, orderBy)
assert.NoError(t, err, "Unexpected error getting members")
assert.Equal(t, int32(1), results.Count, "Incorrect number of results")
}
func TestGetOrganizationMembersBad(t *testing.T) {
teardown := setup()
defer teardown()
limit := 10
query := "foo"
offset := 2
orderBy := "bar"
params := url.Values{}
params.Add("limit", strconv.Itoa(limit))
params.Add("query", query)
params.Add("offset", strconv.Itoa(offset))
params.Add("orderBy", orderBy)
mux.HandleFunc("/v2/organization/member", verifyRequest(t, "GET", true, http.StatusBadRequest, params, ""))
_, err := client.GetOrganizationMembers(context.Background(), limit, query, offset, orderBy)
assert.Error(t, err, "Unexpected error getting members")
}
func TestDeleteMember(t *testing.T) {
teardown := setup()
defer teardown()
mux.HandleFunc("/v2/organization/member/string", verifyRequest(t, "DELETE", true, http.StatusNoContent, nil, ""))
err := client.DeleteMember(context.Background(), "string")
assert.NoError(t, err, "Unexpected error deleting member")
}
func TestDeleteMissingMember(t *testing.T) {
teardown := setup()
defer teardown()
mux.HandleFunc("/v2/organization/member", verifyRequest(t, "POST", true, http.StatusNotFound, nil, ""))
err := client.DeleteMember(context.Background(), "example")
assert.Error(t, err, "Should have gotten an error from a missing delete")
}