Exemple #1
0
func (s *TestSuite) TestDecorate(c *C) {
	var order callOrder
	client := kapusta.Decorate(s.dummyClient, createDecorator("A", &order), createDecorator("B", &order), createDecorator("C", &order))

	client.Do(&http.Request{})

	c.Assert(callOrder{"C", "B", "A"}, DeepEquals, order)
}
Exemple #2
0
func (s *TestSuite) TestPanicDecorator(c *C) {
	panicTriggerDecorator := func(c kapusta.IClient) kapusta.IClient {
		return kapusta.ClientFunc(func(r *http.Request) (res *http.Response, err error) {
			panic("oops")
		})
	}
	r, _ := http.NewRequest("GET", "/", nil)
	client := kapusta.Decorate(s.dummyClient, panicTriggerDecorator, RecoverDecorator())
	res, err := client.Do(r)

	c.Assert(res, IsNil)
	c.Assert(err, ErrorMatches, "*oops")
}
Exemple #3
0
func (s *TestSuite) send(r *http.Request, decorator kapusta.DecoratorFunc) (*http.Response, error) {
	return kapusta.Decorate(s.dummyClient, decorator).Do(r)
}