func (t *HttpConnTest) InvalidScheme() { // Connection _, err := conn.NewHttpConn(&url.URL{Scheme: "taco", Host: "localhost"}) ExpectThat(err, Error(HasSubstr("scheme"))) ExpectThat(err, Error(HasSubstr("taco"))) }
func (t *HttpConnTest) HttpsAllowed() { t.endpoint.Scheme = "https" // Connection _, err := conn.NewHttpConn(t.endpoint) AssertEq(nil, err) }
func (t *HttpConnTest) UnknownHost() { // Connection c, err := conn.NewHttpConn(&url.URL{Scheme: "http", Host: "foo.sidofhdksjhf"}) AssertEq(nil, err) // Request req := conn.Request{} // Call _, err = c.SendRequest(req) ExpectThat(err, Error(HasSubstr("foo.sidofhdksjhf"))) ExpectThat(err, Error(HasSubstr("no such host"))) }
func (t *HttpConnTest) RequestContainsNoParameters() { // Connection c, err := conn.NewHttpConn(t.endpoint) AssertEq(nil, err) // Request req := conn.Request{} // Call _, err = c.SendRequest(req) AssertEq(nil, err) AssertNe(nil, t.handler.reqBody) ExpectEq(0, len(t.handler.reqBody), "Body: %s", t.handler.reqBody) }
func (t *HttpConnTest) ServerReturnsEmptyBody() { // Handler t.handler.body = []byte{} // Connection c, err := conn.NewHttpConn(t.endpoint) AssertEq(nil, err) // Request req := conn.Request{} // Call resp, err := c.SendRequest(req) AssertEq(nil, err) ExpectThat(resp.Body, ElementsAre()) }
func (t *HttpConnTest) ReturnsBody() { // Handler t.handler.body = []byte{0xde, 0xad, 0x00, 0xbe, 0xef} // Connection c, err := conn.NewHttpConn(t.endpoint) AssertEq(nil, err) // Request req := conn.Request{} // Call resp, err := c.SendRequest(req) AssertEq(nil, err) ExpectThat(resp.Body, DeepEquals(t.handler.body)) }
func (t *HttpConnTest) ReturnsStatusCode() { // Handler t.handler.statusCode = 123 // Connection c, err := conn.NewHttpConn(t.endpoint) AssertEq(nil, err) // Request req := conn.Request{} // Call resp, err := c.SendRequest(req) AssertEq(nil, err) ExpectEq(123, resp.StatusCode) }
func (t *HttpConnTest) RequestContainsOneParameter() { // Connection c, err := conn.NewHttpConn(t.endpoint) AssertEq(nil, err) // Request req := conn.Request{ "taco": "burrito", } // Call _, err = c.SendRequest(req) AssertEq(nil, err) AssertNe(nil, t.handler.reqBody) ExpectEq( "taco=burrito", string(t.handler.reqBody)) }
func (t *HttpConnTest) ParametersNeedEscaping() { // Connection c, err := conn.NewHttpConn(t.endpoint) AssertEq(nil, err) // Request req := conn.Request{ "타코": "burrito", "b&az=": "qu?%x", "a+b": "c d", } // Call _, err = c.SendRequest(req) AssertEq(nil, err) AssertNe(nil, t.handler.reqBody) components := strings.Split(string(t.handler.reqBody), "&") AssertThat(components, ElementsAre(Any(), Any(), Any())) ExpectThat(components, Contains("%ED%83%80%EC%BD%94=burrito")) ExpectThat(components, Contains("b%26az%3D=qu%3F%25x")) ExpectThat(components, Contains("a%2Bb=c%20d")) }
func (t *HttpConnTest) RequestContainsMultipleParameters() { // Connection c, err := conn.NewHttpConn(t.endpoint) AssertEq(nil, err) // Request req := conn.Request{ "taco": "burrito", "enchilada": "queso", "nachos": "carnitas", } // Call _, err = c.SendRequest(req) AssertEq(nil, err) AssertNe(nil, t.handler.reqBody) components := strings.Split(string(t.handler.reqBody), "&") AssertThat(components, ElementsAre(Any(), Any(), Any())) ExpectThat(components, Contains("taco=burrito")) ExpectThat(components, Contains("enchilada=queso")) ExpectThat(components, Contains("nachos=carnitas")) }
func (t *HttpConnTest) BasicHttpInfo() { // Connection c, err := conn.NewHttpConn(t.endpoint) AssertEq(nil, err) // Request req := conn.Request{} // Call _, err = c.SendRequest(req) AssertEq(nil, err) AssertNe(nil, t.handler.req) sysReq := t.handler.req ExpectEq("POST", sysReq.Method) ExpectEq("/", sysReq.URL.Path) ExpectEq(t.endpoint.Host, sysReq.Host) ExpectThat( sysReq.Header["Content-Type"], ElementsAre("application/x-www-form-urlencoded; charset=utf-8")) }