This repository has been archived by the owner on Apr 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcloudflare_query_test.go
92 lines (74 loc) · 1.95 KB
/
cloudflare_query_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
package main_test
import (
. "github.com/alphagov/cloudflare-configure"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"io/ioutil"
"net/http"
"strings"
)
const (
headerEmail = "X-Auth-Email"
headerKey = "X-Auth-Key"
authEmail = "[email protected]"
authKey = "abc123"
)
var _ = Describe("CloudFlareQuery", func() {
var (
err error
query CloudFlareQuery
req *http.Request
)
BeforeEach(func() {
query = CloudFlareQuery{
RootURL: "https://example.com/api",
AuthEmail: authEmail,
AuthKey: authKey,
}
})
Describe("MakeRequest", func() {
BeforeEach(func() {
req, err = query.NewRequest("GET", "/zones")
})
It("should return request and no errors", func() {
Expect(req).ToNot(BeNil())
Expect(err).To(BeNil())
})
It("should set method and path", func() {
Expect(req.Method).To(Equal("GET"))
Expect(req.URL.String()).To(Equal("https://example.com/api/zones"))
})
It("should not set request body", func() {
Expect(req.Body).To(BeNil())
})
It("should set Content-Type to JSON", func() {
Expect(req.Header.Get("Content-Type")).To(Equal("application/json"))
})
It("should set authentication email and key header", func() {
Expect(req.Header.Get(headerEmail)).To(Equal(authEmail))
Expect(req.Header.Get(headerKey)).To(Equal(authKey))
})
})
Describe("MakeRequestBody", func() {
const body = `{"foo": "bar"}`
BeforeEach(func() {
req, err = query.NewRequestBody(
"PATCH", "/settings", strings.NewReader(body),
)
})
It("should return request and no errors", func() {
Expect(req).ToNot(BeNil())
Expect(err).To(BeNil())
})
It("should set method and URL", func() {
Expect(req.Method).To(Equal("PATCH"))
Expect(req.URL.String()).To(Equal("https://example.com/api/settings"))
})
It("should set request body", func() {
buf, err := ioutil.ReadAll(req.Body)
defer req.Body.Close()
Expect(err).To(BeNil())
Expect(buf).To(MatchJSON(body))
})
})
})