Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make test output honor output.logstash.proxy_url #154

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions transport/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"net"
"net/url"
"sync"
"time"

Expand Down Expand Up @@ -215,19 +216,38 @@ func (c *Client) handleError(err error) error {

func (c *Client) Test(d testing.Driver) {
d.Run("logstash: "+c.host, func(d testing.Driver) {
if c.config.Proxy.URL != "" {
d.Run("proxy", func(d testing.Driver) {
url, err1 := url.Parse(c.config.Proxy.URL)
d.Fatal("parse url", err1)
dialer := TestNetDialer(d, c.config.Timeout)
_, err2 := dialer.Dial("tcp", url.Host)
d.Fatal("dial up", err2)
})
}

d.Run("connection", func(d testing.Driver) {
netDialer := TestNetDialer(d, c.config.Timeout)
_, err := netDialer.Dial("tcp", c.host)
var dialer Dialer
if c.config.Proxy.URL == "" {
dialer = TestNetDialer(d, c.config.Timeout)
} else {
dialer = NetDialer(c.config.Timeout)
dialer = testProxyDialer(d, dialer, c.config.Proxy)
}
_, err := dialer.Dial("tcp", c.host)
d.Fatal("dial up", err)
})

if c.config.TLS == nil {
d.Warn("TLS", "secure connection disabled")
} else {
d.Run("TLS", func(d testing.Driver) {
netDialer := NetDialer(c.config.Timeout)
tlsDialer := TestTLSDialer(d, netDialer, c.config.TLS, c.config.Timeout)
_, err := tlsDialer.Dial("tcp", c.host)
dialer := NetDialer(c.config.Timeout)
if c.config.Proxy.URL != "" {
dialer = testProxyDialer(d, dialer, c.config.Proxy)
}
dialer = TestTLSDialer(d, dialer, c.config.TLS, c.config.Timeout)
_, err := dialer.Dial("tcp", c.host)
d.Fatal("dial up", err)
})
}
Expand Down
11 changes: 11 additions & 0 deletions transport/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"golang.org/x/net/proxy"

"github.com/elastic/elastic-agent-libs/logp"
"github.com/elastic/elastic-agent-libs/testing"
)

// ProxyConfig holds the configuration information required to proxy
Expand Down Expand Up @@ -97,3 +98,13 @@ func ProxyDialer(log *logp.Logger, config *ProxyConfig, forward Dialer) (Dialer,
return DialWith(dialer, network, host, addresses, port)
}), nil
}

func testProxyDialer(
d testing.Driver,
forward Dialer,
config *ProxyConfig,
) Dialer {
dialer, err := ProxyDialer(logp.L(), config, forward)
d.Fatal("proxy", err)
return dialer
}
Loading