-
Notifications
You must be signed in to change notification settings - Fork 24
/
products_test.go
80 lines (69 loc) · 1.93 KB
/
products_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
package apigee
import (
"encoding/json"
"testing"
"math/rand"
)
const (
productJson1 = `{
"apiResources" : [ ],
"approvalType" : "auto",
"attributes" : [ {
"name" : "category",
"value" : "Flight Operations, Reservations"
}, {
"name" : "image_url",
"value" : "http://i.cdn.turner.com/cnn/2010/TRAVEL/11/18/flying.driving.travel.apps/t1larg.flight.status.jpg"
} ],
"description" : "",
"displayName" : "FlightStatus",
"environments" : [ "test" ],
"name" : "FlightStatus",
"proxies" : [ "will-be-replaced" ],
"scopes" : [ "" ]
}`
)
func randomProductFromTemplate(proxyname string) (ApiProduct, error) {
// just a way to quickly set values to a few defaults
got := ApiProduct{}
e := json.Unmarshal([]byte(productJson1), &got)
if e != nil {
return got, e
}
// assign values
tag := testPrefix + randomString(7)
got.Name = tag + "-" + got.Name
got.Proxies = []string{proxyname}
got.DisplayName = tag + "-" + got.DisplayName
got.Description = tag + " " + randomString(8) + " " + randomString(18)
got.Scopes = []string { randomString(1), randomString(2), }
return got, e
}
func TestProductCreateDelete(t *testing.T) {
client := NewClientForTesting(t)
namelist, resp, e := client.Proxies.List()
if e != nil {
t.Errorf("while listing proxies, error:\n%#v\n", e)
return
}
if len(namelist) <= 0 {
t.Errorf("no proxies found")
return
}
selectedProxy := namelist[rand.Intn(len(namelist))]
product, e := randomProductFromTemplate(selectedProxy)
createdProduct, resp, e := client.Products.Create(product)
if e != nil {
t.Errorf("while creating Apigee product, error:\n%#v\n", e)
return
}
t.Logf("Create: got=%v", createdProduct)
t.Logf("resp: got=%v", resp)
wait(1)
deletedProduct, resp, e := client.Products.Delete(createdProduct.Name)
if e != nil {
t.Errorf("while deleting Apigee product, error:\n%#v\n", e)
return
}
t.Logf("Delete: got=%v", deletedProduct)
}