-
Notifications
You must be signed in to change notification settings - Fork 24
/
developerapps_test.go
120 lines (101 loc) · 2.51 KB
/
developerapps_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
package apigee
import (
"encoding/json"
"testing"
)
const (
appJson1 = `{
"attributes": [ {
"name" : "tag1",
"value" : "created by golang" }],
"name" : "will-be-replaced",
"keyExpiresIn" : "3600000"
}`
)
func randomAppFromTemplate() (DeveloperApp, error) {
got := DeveloperApp{}
e := json.Unmarshal([]byte(appJson1), &got)
if e != nil {
return got, e
}
// assign values
tag := testPrefix + randomString(7)
got.Name = tag + "app"
return got, e
}
func TestDeveloperAppCreateDelete(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)
teardown := func(t *testing.T) {
t.Logf("remove developer")
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)
devapps := client.Developers.Apps(createdDeveloper.Email)
devapp, e := randomAppFromTemplate()
createdApp, resp, e := devapps.Create(devapp)
if e != nil {
t.Errorf("while creating developer app, error:\n%#v\n", e)
return
}
t.Logf("CreateApp: got=%v", createdApp)
wait(1)
resp, e = devapps.Revoke(createdApp.Name)
if e != nil {
t.Errorf("while revoking developer app, error:\n%#v\n", e)
return
}
t.Logf("RevokeApp")
wait(1)
got, resp, e := devapps.Get(createdApp.Name)
if e != nil {
t.Errorf("while getting developer app, error:\n%#v\n", e)
return
}
if (got.Name != createdApp.Name) {
t.Errorf("inconsistent name")
}
if (got.Status != "revoked") {
t.Errorf("inconsistent status")
}
t.Logf("GetApp")
resp, e = devapps.Approve(createdApp.Name)
if e != nil {
t.Errorf("while approving developer app, error:\n%#v\n", e)
return
}
t.Logf("ApproveApp")
wait(1)
got, resp, e = devapps.Get(createdApp.Name)
if e != nil {
t.Errorf("while getting developer app, error:\n%#v\n", e)
return
}
if (got.Name != createdApp.Name) {
t.Errorf("inconsistent name")
}
if (got.Status != "approved") {
t.Errorf("inconsistent status")
}
t.Logf("GetApp")
deletedApp, resp, e := devapps.Delete(createdApp.Name)
if e != nil {
t.Errorf("while creating developer app, error:\n%#v\n", e)
return
}
t.Logf("DeleteApp: got=%v", deletedApp)
wait(1)
}