Skip to content

Commit

Permalink
More tests and unix socket support
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob Shannon committed Apr 17, 2018
1 parent 8e1c686 commit ff3d682
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
8 changes: 8 additions & 0 deletions plugins/inputs/socket_listener/socket_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,14 @@ func (uc unixCloser) Close() error {
return err
}

func (uc unixCloser) Accept() (net.Conn, error) {
return uc.closer.(net.Listener).Accept()
}

func (uc unixCloser) Addr() net.Addr {
return uc.closer.(net.Listener).Addr()
}

func init() {
inputs.Add("socket_listener", func() telegraf.Input { return newSocketListener() })
}
25 changes: 24 additions & 1 deletion plugins/inputs/socket_listener/socket_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func testEmptyLog(t *testing.T) func() {
}
}

func TestSocketListener_tls(t *testing.T) {
func TestSocketListener_tcp_tls(t *testing.T) {
defer testEmptyLog(t)()

sl := newSocketListener()
Expand All @@ -50,6 +50,29 @@ func TestSocketListener_tls(t *testing.T) {
testSocketListener(t, sl, secureClient)
}

func TestSocketListener_unix_tls(t *testing.T) {
defer testEmptyLog(t)()

sl := newSocketListener()
sl.ServiceAddress = "unix:///tmp/telegraf_test.sock"
sl.TLSCert = "testdata/server.pem"
sl.TLSKey = "testdata/server.key"
sl.TLSAllowedCACerts = []string{"testdata/ca.pem"}

acc := &testutil.Accumulator{}
err := sl.Start(acc)
require.NoError(t, err)
defer sl.Stop()

tlsCfg, err := internal.GetTLSConfig("testdata/client.pem", "testdata/client.key", "testdata/ca.pem", true)
require.NoError(t, err)

secureClient, err := tls.Dial("unix", "/tmp/telegraf_test.sock", tlsCfg)
require.NoError(t, err)

testSocketListener(t, sl, secureClient)
}

func TestSocketListener_tcp(t *testing.T) {
defer testEmptyLog(t)()

Expand Down

0 comments on commit ff3d682

Please sign in to comment.