-
Notifications
You must be signed in to change notification settings - Fork 24
/
developers_test.go
128 lines (110 loc) · 2.96 KB
/
developers_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
package apigee
import (
"encoding/json"
"testing"
"math/rand"
)
const (
developerJson1 = `{
"attributes": [ {
"name" : "tag1",
"value" : "created by golang" }],
"status": "active",
"userName": "username",
"lastName": "Martino",
"firstName": "Dino",
"email": "@apigee.com",
"companies": [],
"apps": []
}`
)
func randomDeveloperFromTemplate() (Developer, error) {
got := Developer{}
e := json.Unmarshal([]byte(developerJson1), &got)
if e != nil {
return got, e
}
// assign values
tag := testPrefix + randomString(6)
got.Email = tag + got.Email
got.UserName = tag + "-" + got.UserName
got.FirstName = got.FirstName + "-" + tag
return got, e
}
func TestDeveloperCreateDelete(t *testing.T) {
client := NewClientForTesting(t)
dev, e := randomDeveloperFromTemplate()
createdDeveloper, resp, e := client.Developers.Create(dev)
if e != nil {
t.Errorf("while creating Edge developer, error:\n%#v\n", e)
return
}
t.Logf("Create: got=%+v", createdDeveloper)
t.Logf("resp: got=%+v", resp)
wait(1)
deletedDeveloper, resp, e := client.Developers.Delete(createdDeveloper.Email)
if e != nil {
t.Errorf("while deleting Edge developer, error:\n%#v\n", e)
return
}
t.Logf("Delete: got=%v", deletedDeveloper)
}
func TestDeveloperList(t *testing.T) {
client := NewClientForTesting(t)
developerList, _, e := client.Developers.List()
if e != nil {
t.Errorf("while listing Edge developers, error:\n%#v\n", e)
return
}
t.Logf("List: got=%+v", developerList)
}
func TestDeveloperGet(t *testing.T) {
client := NewClientForTesting(t)
developerList, _, e := client.Developers.List()
if e != nil {
t.Errorf("while listing Edge developers, error:\n%#v\n", e)
return
}
selectedDevEmail := developerList[rand.Intn(len(developerList))]
developerDetails, _, e := client.Developers.Get(selectedDevEmail)
if e != nil {
t.Errorf("while getting Edge developer, error:\n%#v\n", e)
return
}
t.Logf("Get: selected=%+v", developerDetails)
t.Logf("Get: email=%s", developerDetails.Email)
}
func TestDeveloperUpdate(t *testing.T) {
client := NewClientForTesting(t)
dev, e := randomDeveloperFromTemplate()
createdDeveloper, _, e := client.Developers.Create(dev)
if e != nil {
t.Errorf("while creating Edge developer, error:\n%#v\n", e)
return
}
t.Logf("Create: got=%+v", createdDeveloper)
teardown := func(t *testing.T) {
deletedDeveloper, _, e := client.Developers.Delete(createdDeveloper.Email)
if e != nil {
t.Errorf("while deleting Edge developer, error:\n%#v\n", e)
return
}
t.Logf("Delete: got=%v", deletedDeveloper)
}
defer teardown(t)
wait(1)
_, e = client.Developers.Revoke(createdDeveloper.Email)
if e != nil {
t.Errorf("while revoking Edge developer, error:\n%#v\n", e)
return
}
t.Logf("Revoke")
wait(1)
_, e = client.Developers.Approve(createdDeveloper.Email)
if e != nil {
t.Errorf("while approving Edge developer, error:\n%#v\n", e)
return
}
t.Logf("Approve")
wait(1)
}