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

Fix tests for Windows - part 1 #8414

Merged
merged 19 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Fix tests for Windows - part 1 (enable tests for syslog plugin)
  • Loading branch information
pzak committed Nov 22, 2020
commit 47bc7f0377b325e08ddc129f386907966a6b4b34
4 changes: 0 additions & 4 deletions plugins/inputs/syslog/commons_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
//+build !windows

// TODO: Windows - should be enabled for Windows when tests are ready for this OS

package syslog

import (
Expand Down
7 changes: 2 additions & 5 deletions plugins/inputs/syslog/nontransparent_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
//+build !windows

// TODO: Windows - should be enabled for Windows when tests are ready for this OS

package syslog

import (
Expand All @@ -13,11 +9,12 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
framing "github.com/influxdata/telegraf/internal/syslog"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/require"
)

func getTestCasesForNonTransparent() []testCaseStream {
Expand Down
7 changes: 2 additions & 5 deletions plugins/inputs/syslog/octetcounting_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
//+build !windows

// TODO: Windows - should be enabled for Windows when tests are ready for this OS

package syslog

import (
Expand All @@ -14,11 +10,12 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
framing "github.com/influxdata/telegraf/internal/syslog"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/require"
)

func getTestCasesForOctetCounting() []testCaseStream {
Expand Down
16 changes: 11 additions & 5 deletions plugins/inputs/syslog/rfc5426_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
//+build !windows

// TODO: Windows - should be enabled for Windows when tests are ready for this OS

package syslog

import (
Expand All @@ -10,13 +6,15 @@ import (
"net"
"os"
"path/filepath"
"runtime"
"sync/atomic"
"testing"
"time"

"github.com/stretchr/testify/require"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/require"
)

func getTestCasesForRFC5426() []testCasePacket {
Expand Down Expand Up @@ -288,6 +286,10 @@ func TestStrict_udp(t *testing.T) {
}

func TestBestEffort_unixgram(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping on Windows, as unixgram sockets are not supported")
}

tmpdir, err := ioutil.TempDir("", "telegraf")
require.NoError(t, err)
defer os.RemoveAll(tmpdir)
Expand All @@ -297,6 +299,10 @@ func TestBestEffort_unixgram(t *testing.T) {
}

func TestStrict_unixgram(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping on Windows, as unixgram sockets are not supported")
}

tmpdir, err := ioutil.TempDir("", "telegraf")
require.NoError(t, err)
defer os.RemoveAll(tmpdir)
Expand Down
7 changes: 6 additions & 1 deletion plugins/inputs/syslog/syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net"
"net/url"
"os"
"path/filepath"
"strings"
"sync"
"time"
Expand All @@ -16,6 +17,7 @@ import (
"github.com/influxdata/go-syslog/v2/nontransparent"
"github.com/influxdata/go-syslog/v2/octetcounting"
"github.com/influxdata/go-syslog/v2/rfc5424"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
framing "github.com/influxdata/telegraf/internal/syslog"
Expand Down Expand Up @@ -195,7 +197,10 @@ func getAddressParts(a string) (string, string, error) {
return "", "", fmt.Errorf("missing protocol within address '%s'", a)
}

u, _ := url.Parse(a)
u, err := url.Parse(filepath.ToSlash(a)) //convert backslashes to slashes (to make Windows path a valid URL)
if err != nil {
return "", "", fmt.Errorf("could not parse address '%s': %v", a, err)
}
switch u.Scheme {
case "unix", "unixpacket", "unixgram":
return parts[0], parts[1], nil
Expand Down
23 changes: 12 additions & 11 deletions plugins/inputs/syslog/syslog_test.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
//+build !windows

// TODO: Windows - should be enabled for Windows when tests are ready for this OS

package syslog

import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"time"

"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/require"

"github.com/influxdata/telegraf/testutil"
)

const (
Expand Down Expand Up @@ -53,13 +51,16 @@ func TestAddress(t *testing.T) {
require.NoError(t, err)
sock := filepath.Join(tmpdir, "syslog.TestAddress.sock")

rec = &Syslog{
Address: "unixgram://" + sock,
if runtime.GOOS != "windows" {
// Skipping on Windows, as unixgram sockets are not supported
rec = &Syslog{
Address: "unixgram://" + sock,
}
err = rec.Start(&testutil.Accumulator{})
require.NoError(t, err)
require.Equal(t, sock, rec.Address)
rec.Stop()
}
err = rec.Start(&testutil.Accumulator{})
require.NoError(t, err)
require.Equal(t, sock, rec.Address)
rec.Stop()

// Default port is 6514
rec = &Syslog{
Expand Down