Skip to content

Commit

Permalink
Export Kibana Client's Transport and Version (elastic#12422)
Browse files Browse the repository at this point in the history
Required to mock a Kibana connection outside its own package
  • Loading branch information
jalvz authored and andrewvc committed Jun 12, 2019
1 parent 338fabb commit 03752cd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions libbeat/kibana/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ type Connection struct {
Username string
Password string

http *http.Client
version common.Version
HTTP *http.Client
Version common.Version
}

type Client struct {
Expand Down Expand Up @@ -134,7 +134,7 @@ func NewClientWithConfig(config *ClientConfig) (*Client, error) {
URL: kibanaURL,
Username: username,
Password: password,
http: &http.Client{
HTTP: &http.Client{
Transport: &http.Transport{
Dial: dialer.Dial,
DialTLS: tlsDialer.Dial,
Expand Down Expand Up @@ -195,7 +195,7 @@ func (conn *Connection) Send(method, extraPath string,
req.Header.Add("Accept", "application/json")
req.Header.Set("kbn-xsrf", "1")
if method != "GET" {
req.Header.Set("kbn-version", conn.version.String())
req.Header.Set("kbn-version", conn.Version.String())
}

for header, values := range headers {
Expand All @@ -209,7 +209,7 @@ func (conn *Connection) Send(method, extraPath string,

// Implements RoundTrip interface
func (conn *Connection) RoundTrip(r *http.Request) (*http.Response, error) {
return conn.http.Do(r)
return conn.HTTP.Do(r)
}

func (client *Client) readVersion() error {
Expand Down Expand Up @@ -253,13 +253,13 @@ func (client *Client) readVersion() error {
return fmt.Errorf("fail to parse kibana version (%v): %+v", versionString, err)
}

client.version = *version
client.Version = *version
return nil
}

// GetVersion returns the version read from kibana. The version is not set if
// IgnoreVersion was set when creating the client.
func (client *Client) GetVersion() common.Version { return client.version }
func (client *Client) GetVersion() common.Version { return client.Version }

func (client *Client) ImportJSON(url string, params url.Values, jsonBody map[string]interface{}) error {

Expand Down
6 changes: 3 additions & 3 deletions libbeat/kibana/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestErrorJson(t *testing.T) {

conn := Connection{
URL: kibanaTs.URL,
http: http.DefaultClient,
HTTP: http.DefaultClient,
}
code, _, err := conn.Request(http.MethodPost, "", url.Values{}, nil, nil)
assert.Equal(t, http.StatusOK, code)
Expand All @@ -50,7 +50,7 @@ func TestErrorBadJson(t *testing.T) {

conn := Connection{
URL: kibanaTs.URL,
http: http.DefaultClient,
HTTP: http.DefaultClient,
}
code, _, err := conn.Request(http.MethodPost, "", url.Values{}, nil, nil)
assert.Equal(t, http.StatusOK, code)
Expand All @@ -68,7 +68,7 @@ func TestSuccess(t *testing.T) {

conn := Connection{
URL: kibanaTs.URL,
http: http.DefaultClient,
HTTP: http.DefaultClient,
}
code, _, err := conn.Request(http.MethodPost, "", url.Values{}, http.Header{"foo": []string{"bar"}}, nil)
assert.Equal(t, http.StatusOK, code)
Expand Down

0 comments on commit 03752cd

Please sign in to comment.