2018-05-25 18:40:12 +00:00
|
|
|
package syslog
|
|
|
|
|
|
|
|
import (
|
2018-06-04 02:43:06 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2018-05-25 18:40:12 +00:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/influxdata/telegraf/testutil"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
address = ":6514"
|
|
|
|
)
|
|
|
|
|
|
|
|
var defaultTime = time.Unix(0, 0)
|
|
|
|
var maxP = uint8(191)
|
|
|
|
var maxV = uint16(999)
|
|
|
|
var maxTS = "2017-12-31T23:59:59.999999+00:00"
|
|
|
|
var maxH = "abcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabc"
|
|
|
|
var maxA = "abcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdef"
|
|
|
|
var maxPID = "abcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzab"
|
|
|
|
var maxMID = "abcdefghilmnopqrstuvzabcdefghilm"
|
|
|
|
var message7681 = strings.Repeat("l", 7681)
|
|
|
|
|
|
|
|
func TestAddress(t *testing.T) {
|
|
|
|
var err error
|
|
|
|
var rec *Syslog
|
|
|
|
|
|
|
|
rec = &Syslog{
|
|
|
|
Address: "localhost:6514",
|
|
|
|
}
|
|
|
|
err = rec.Start(&testutil.Accumulator{})
|
|
|
|
require.EqualError(t, err, "missing protocol within address 'localhost:6514'")
|
|
|
|
require.Error(t, err)
|
|
|
|
|
|
|
|
rec = &Syslog{
|
|
|
|
Address: "unsupported://example.com:6514",
|
|
|
|
}
|
|
|
|
err = rec.Start(&testutil.Accumulator{})
|
|
|
|
require.EqualError(t, err, "unknown protocol 'unsupported' in 'example.com:6514'")
|
|
|
|
require.Error(t, err)
|
|
|
|
|
2018-06-04 02:43:06 +00:00
|
|
|
tmpdir, err := ioutil.TempDir("", "telegraf")
|
|
|
|
defer os.RemoveAll(tmpdir)
|
|
|
|
require.NoError(t, err)
|
|
|
|
sock := filepath.Join(tmpdir, "syslog.TestAddress.sock")
|
|
|
|
|
2018-05-25 18:40:12 +00:00
|
|
|
rec = &Syslog{
|
2018-06-04 02:43:06 +00:00
|
|
|
Address: "unixgram://" + sock,
|
2018-05-25 18:40:12 +00:00
|
|
|
}
|
|
|
|
err = rec.Start(&testutil.Accumulator{})
|
|
|
|
require.NoError(t, err)
|
2018-06-04 02:43:06 +00:00
|
|
|
require.Equal(t, sock, rec.Address)
|
2018-05-25 18:40:12 +00:00
|
|
|
rec.Stop()
|
|
|
|
|
|
|
|
// Default port is 6514
|
|
|
|
rec = &Syslog{
|
|
|
|
Address: "tcp://localhost",
|
|
|
|
}
|
|
|
|
err = rec.Start(&testutil.Accumulator{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, "localhost:6514", rec.Address)
|
|
|
|
rec.Stop()
|
|
|
|
}
|