I've written some tests in Go using Ginkgo/Gomega, but no matter what I do, ghttp
returns a 500 status to my client with no content. Here is some sample code:
var _ = Describe("Client", func() {
var (
server *ghttp.Server
)
BeforeEach(func() {
server = ghttp.NewServer()
server.AllowUnhandledRequests = false
server.Writer = GinkgoWriter
})
AfterEach(func() {
server.Close()
})
Describe("fetching a node list", func() {
BeforeEach(func() {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/nodes"),
ghttp.RespondWith(204, ""),
),
)
})
It("should be able to fetch a node list", func() {
response, err := myclient.Get(NODES)
Ω(err).ShouldNot(HaveOccurred())
Ω(response).ShouldNot(BeNil(), "No response was returned from nodes.")
data, err := httputil.DumpResponse(response, true)
Ω(err).ShouldNot(HaveOccurred())
GinkgoWriter.Write(data)
Ω(response.StatusCode).Should(Equal(204))
})
})
})
According to the Gomega changelog:
If a registered handler makes a failing assertion ghttp will return 500.
If a registered handler panics, ghttp will return 500 and fail the test.
However, I can't get these tests to fail, even if I post to a different route, remove the append handlers call, etc. Any suggestions would be appreciated!