2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
27 func TestHttpClient(t *testing.T) {
28 l, addr := HttpClientSetupForTest(t)
32 trans, err := NewTHttpPostClient("http://" + addr.String())
35 t.Fatalf("Unable to connect to %s: %s", addr.String(), err)
37 TransportTest(t, trans, trans)
40 func TestHttpClientHeaders(t *testing.T) {
41 l, addr := HttpClientSetupForTest(t)
45 trans, err := NewTHttpPostClient("http://" + addr.String())
48 t.Fatalf("Unable to connect to %s: %s", addr.String(), err)
50 TransportHeaderTest(t, trans, trans)
53 func TestHttpCustomClient(t *testing.T) {
54 l, addr := HttpClientSetupForTest(t)
59 httpTransport := &customHttpTransport{}
61 trans, err := NewTHttpPostClientWithOptions("http://"+addr.String(), THttpClientOptions{
63 Transport: httpTransport,
68 t.Fatalf("Unable to connect to %s: %s", addr.String(), err)
70 TransportHeaderTest(t, trans, trans)
72 if !httpTransport.hit {
73 t.Fatalf("Custom client was not used")
77 func TestHttpCustomClientPackageScope(t *testing.T) {
78 l, addr := HttpClientSetupForTest(t)
82 httpTransport := &customHttpTransport{}
83 DefaultHttpClient = &http.Client{
84 Transport: httpTransport,
87 trans, err := NewTHttpPostClient("http://" + addr.String())
90 t.Fatalf("Unable to connect to %s: %s", addr.String(), err)
92 TransportHeaderTest(t, trans, trans)
94 if !httpTransport.hit {
95 t.Fatalf("Custom client was not used")
99 type customHttpTransport struct {
103 func (c *customHttpTransport) RoundTrip(req *http.Request) (*http.Response, error) {
105 return http.DefaultTransport.RoundTrip(req)