本文整理汇总了Golang中github.com/onsi/gomega/ghttp.Server.GetHandler方法的典型用法代码示例。如果您正苦于以下问题:Golang Server.GetHandler方法的具体用法?Golang Server.GetHandler怎么用?Golang Server.GetHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/onsi/gomega/ghttp.Server
的用法示例。
在下文中一共展示了Server.GetHandler方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1:
),
)
})
AfterEach(func() {
ccServer.Close()
})
It("tries to create the app", func() {
repo.Create(appParams)
Expect(ccServer.ReceivedRequests()).To(HaveLen(1))
})
Context("when the create succeeds", func() {
BeforeEach(func() {
h := ccServer.GetHandler(0)
ccServer.SetHandler(0,
ghttp.CombineHandlers(
h,
ghttp.RespondWith(http.StatusCreated, `{
"metadata": {
"guid": "my-cool-app-guid"
},
"entity": {
"name": "my-cool-app"
}
}`),
),
)
})
示例2:
It("Should create 'get' command with proper name", func() {
Expect(getCommand.Name).To(Equal("tower show"))
})
It("Should get resource successfully", func() {
result, err := getCommand.Action([]string{icyTowerID})
Expect(err).ToNot(HaveOccurred())
var resultJSON interface{}
json.Unmarshal([]byte(result), &resultJSON)
Expect(resultJSON).To(Equal(getIcyTower()))
})
It("Should get resource by name successfully", func() {
server.SetHandler(1, ghttp.RespondWith(404, nil))
handler := server.GetHandler(2)
server.SetHandler(2, ghttp.RespondWithJSONEncoded(200, getIcyTowerListResponse()))
server.AppendHandlers(handler)
result, err := getCommand.Action([]string{icyTowerName})
Expect(err).ToNot(HaveOccurred())
var resultJSON interface{}
json.Unmarshal([]byte(result), &resultJSON)
Expect(resultJSON).To(Equal(getIcyTower()))
})
It("Should show error - wrong number of arguments", func() {
result, err := getCommand.Action([]string{})
Expect(result).To(Equal(""))
Expect(err).To(MatchError("Wrong number of arguments"))
})