-
Notifications
You must be signed in to change notification settings - Fork 24
/
package_test.go
60 lines (50 loc) · 1.26 KB
/
package_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
package apigee
import (
"testing"
"fmt"
"encoding/json"
"io/ioutil"
"time"
"math/rand"
)
const (
letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
testPrefix = "go-test"
testConfigFile = "testdata/test_config.json"
)
var apigeeClient ApigeeClient
var testSettings struct {
Orgname string `json:"orgname"`
Notes string `json:"notes"`
}
func init() {
rand.Seed(time.Now().Unix()) // initialize global pseudo random generator
file, e := ioutil.ReadFile(testConfigFile)
if e != nil {
fmt.Printf("reading configuration file: %#v\n", e)
}
e = json.Unmarshal(file, &testSettings)
if e != nil {
fmt.Printf("unmarshaling configuration: %#v\n", e)
}
}
func NewClientForTesting(t *testing.T) *ApigeeClient {
opts := &ApigeeClientOptions{Org: testSettings.Orgname, Auth: nil, Debug: false }
client, e := NewApigeeClient(opts)
if e != nil {
t.Errorf("while initializing Edge client, error:\n%#v\n", e)
return nil
}
return client
}
func wait(delay int) {
fmt.Printf("Waiting %ds...\n", delay)
time.Sleep(time.Duration(delay)*time.Second)
}
func randomString(length int) string {
b := make([]byte, length)
for i := range b {
b[i] = letterBytes[rand.Int63() % int64(len(letterBytes))]
}
return string(b)
}