-
Notifications
You must be signed in to change notification settings - Fork 18
/
client_test.go
88 lines (77 loc) · 2.04 KB
/
client_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
package runscope
import (
"encoding/json"
"log"
"os"
"strings"
"testing"
)
var teamID string
func TestDeserializeResult(t *testing.T) {
responseBody := `
{
"meta": {
"status": "success"
},
"data": {
"verify_ssl": true,
"trigger_url": "https://api.runscope.com/radar/bucket/2e15499d-2e32-4ea8-b6c9-18468031c491/trigger",
"name": "foo",
"key": "6t0sd3euxlwa",
"team": {
"name": "form3",
"id": "870ed937-bc6e-4d8b-a9a5-d7f9f2412fa3"
},
"default": false,
"auth_token": null,
"tests_url": "https://api.runscope.com/buckets/6t0sd3euxlwa/tests",
"collections_url": "https://api.runscope.com/buckets/6t0sd3euxlwa/collections",
"messages_url": "https://api.runscope.com/buckets/6t0sd3euxlwa/stream"
},
"error": null
}
`
response := response{}
err := json.Unmarshal([]byte(responseBody), &response)
if err != nil {
t.Error(err)
}
if response.Data.(map[string]interface{})["key"] != "6t0sd3euxlwa" {
t.Error("Key not deserialized")
}
}
func clientConfigure() *Client {
return NewClient(APIURL, os.Getenv("RUNSCOPE_ACCESS_TOKEN"))
}
func testPreCheck(t *testing.T) {
skip := os.Getenv("RUNSCOPE_ACC") == ""
if skip {
t.Log("runscope client.go tests require setting RUNSCOPE_ACC")
t.Skip()
}
if v := os.Getenv("RUNSCOPE_ACCESS_TOKEN"); v == "" {
t.Fatal("RUNSCOPE_ACCESS_TOKEN must be set for acceptance tests")
}
if v := os.Getenv("RUNSCOPE_TEAM_ID"); v == "" {
t.Fatal("RUNSCOPE_TEAM_ID must be set for acceptance tests")
}
teamID = os.Getenv("RUNSCOPE_TEAM_ID")
}
func deletePredicate(bucket *Bucket) bool {
if strings.HasPrefix(bucket.Name, "test") || strings.HasSuffix(bucket.Name, "-test") {
DebugF(1, "deleting bucket name: %s key: %s \n", bucket.Name, bucket.Key)
return true
}
return false
}
func TestMain(m *testing.M) {
client := clientConfigure()
if err := client.DeleteBuckets(deletePredicate); err != nil {
log.Fatalln(err)
}
code := m.Run()
if err := client.DeleteBuckets(deletePredicate); err != nil {
log.Fatalln(err)
}
os.Exit(code)
}