forked from joefitzgerald/forecast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
milestones_test.go
68 lines (57 loc) · 1.59 KB
/
milestones_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
package forecast_test
import (
"fmt"
"net/http"
"net/http/httptest"
. "github.com/joefitzgerald/forecast"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Milestones", func() {
Context("Milestones()", func() {
var (
server *httptest.Server
api *API
)
AfterEach(func() {
api = nil
if server == nil {
return
}
server.Close()
server = nil
})
Context("when a response is returned from the server", func() {
BeforeEach(func() {
server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := ReadFile("milestones.json")
fmt.Fprintf(w, "%s", response)
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(http.StatusOK)
}))
api = New(server.URL, "test-token", "987654")
})
It("should return milestones and a nil error", func() {
milestones, err := api.Milestones()
Ω(milestones).ShouldNot(BeNil())
Ω(err).ShouldNot(HaveOccurred())
})
})
Context("when an error is returned from the server", func() {
BeforeEach(func() {
server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := "error"
fmt.Fprintf(w, "%s", response)
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(http.StatusBadRequest)
}))
api = New(server.URL, "test-token", "987654")
})
It("should return an error", func() {
milestones, err := api.Milestones()
Ω(milestones).Should(BeNil())
Ω(err).Should(HaveOccurred())
})
})
})
})