forked from cloudfoundry-attic/nsync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstop_app_handler_test.go
89 lines (71 loc) · 2.16 KB
/
stop_app_handler_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
package handlers_test
import (
"errors"
"net/http"
"net/http/httptest"
"net/url"
"github.com/cloudfoundry-incubator/bbs/fake_bbs"
"github.com/cloudfoundry-incubator/bbs/models"
"github.com/cloudfoundry-incubator/nsync/handlers"
"github.com/pivotal-golang/lager/lagertest"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("StopAppHandler", func() {
var (
logger *lagertest.TestLogger
fakeBBS *fake_bbs.FakeClient
request *http.Request
responseRecorder *httptest.ResponseRecorder
)
BeforeEach(func() {
logger = lagertest.NewTestLogger("test")
fakeBBS = new(fake_bbs.FakeClient)
responseRecorder = httptest.NewRecorder()
var err error
request, err = http.NewRequest("DELETE", "", nil)
Expect(err).NotTo(HaveOccurred())
request.Form = url.Values{
":process_guid": []string{"process-guid"},
}
})
JustBeforeEach(func() {
stopAppHandler := handlers.NewStopAppHandler(logger, fakeBBS)
stopAppHandler.StopApp(responseRecorder, request)
})
It("invokes the bbs to delete the app", func() {
Expect(fakeBBS.RemoveDesiredLRPCallCount()).To(Equal(1))
_, desiredLRP := fakeBBS.RemoveDesiredLRPArgsForCall(0)
Expect(desiredLRP).To(Equal("process-guid"))
})
It("responds with 202 Accepted", func() {
Expect(responseRecorder.Code).To(Equal(http.StatusAccepted))
})
Context("when the bbs fails", func() {
BeforeEach(func() {
fakeBBS.RemoveDesiredLRPReturns(errors.New("oh no"))
})
It("responds with a ServiceUnavailabe error", func() {
Expect(responseRecorder.Code).To(Equal(http.StatusServiceUnavailable))
})
})
Context("when the process guid is missing", func() {
BeforeEach(func() {
request.Form.Del(":process_guid")
})
It("does not call the bbs", func() {
Expect(fakeBBS.RemoveDesiredLRPCallCount()).To(Equal(0))
})
It("responds with 400 Bad Request", func() {
Expect(responseRecorder.Code).To(Equal(http.StatusBadRequest))
})
})
Context("when the lrp doesn't exist", func() {
BeforeEach(func() {
fakeBBS.RemoveDesiredLRPReturns(models.ErrResourceNotFound)
})
It("responds with a 404", func() {
Expect(responseRecorder.Code).To(Equal(http.StatusNotFound))
})
})
})