示例#1
0
func (t *HttpConnTest) InvalidScheme() {
	// Connection
	_, err := conn.NewHttpConn(&url.URL{Scheme: "taco", Host: "localhost"})

	ExpectThat(err, Error(HasSubstr("scheme")))
	ExpectThat(err, Error(HasSubstr("taco")))
}
示例#2
0
func (t *HttpConnTest) HttpsAllowed() {
	t.endpoint.Scheme = "https"

	// Connection
	_, err := conn.NewHttpConn(t.endpoint)
	AssertEq(nil, err)
}
示例#3
0
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")))
}
示例#4
0
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)
}
示例#5
0
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())
}
示例#6
0
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))
}
示例#7
0
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)
}
示例#8
0
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))
}
示例#9
0
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"))
}
示例#10
0
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"))
}
示例#11
0
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"))
}