forked from fastly/go-fastly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfastly_test.go
49 lines (39 loc) · 1007 Bytes
/
fastly_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
package fastly
import (
"sync"
"testing"
"github.com/dnaeon/go-vcr/recorder"
)
// testClient is the test client.
var testClient = DefaultClient()
// testServiceID is the ID of the testing service.
var testServiceID = "7i6HN3TK9wS159v2gPAZ8A"
// testVersionLock is a lock around version creation because the Fastly API
// kinda dies on concurrent requests to create a version.
var testVersionLock sync.Mutex
// testVersion is a new, blank version suitable for testing.
func testVersion(t *testing.T, c *Client) *Version {
testVersionLock.Lock()
defer testVersionLock.Unlock()
v, err := c.CreateVersion(&CreateVersionInput{
Service: testServiceID,
})
if err != nil {
t.Fatal(err)
}
return v
}
func record(t *testing.T, fixture string, f func(*Client)) {
r, err := recorder.New("fixtures/" + fixture)
if err != nil {
t.Fatal(err)
}
defer func() {
if err := r.Stop(); err != nil {
t.Fatal(err)
}
}()
client := DefaultClient()
client.HTTPClient.Transport = r
f(client)
}