From 9814d3d84d30bdd43207cbdb41a06e66bfcd9093 Mon Sep 17 00:00:00 2001 From: Steven Soroka Date: Fri, 8 Jan 2021 17:30:43 -0500 Subject: [PATCH] fix some annoying tests due to ports in use --- plugins/inputs/redfish/redfish_test.go | 18 --------------- plugins/inputs/statsd/statsd_test.go | 4 ++-- plugins/outputs/graphite/graphite_test.go | 28 +++++++++++++++-------- 3 files changed, 20 insertions(+), 30 deletions(-) diff --git a/plugins/inputs/redfish/redfish_test.go b/plugins/inputs/redfish/redfish_test.go index c3c6f0d10..6bd282148 100644 --- a/plugins/inputs/redfish/redfish_test.go +++ b/plugins/inputs/redfish/redfish_test.go @@ -8,7 +8,6 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/influxdata/telegraf" @@ -644,23 +643,6 @@ func checkAuth(r *http.Request, username, password string) bool { return user == username && pass == password } -func TestConnection(t *testing.T) { - r := &Redfish{ - Address: "http://127.0.0.1", - Username: "test", - Password: "test", - ComputerSystemId: "System.Embedded.1", - } - - var acc testutil.Accumulator - r.Init() - err := r.Gather(&acc) - if assert.Error(t, err) { - _, ok := err.(*url.Error) - assert.True(t, ok) - } -} - func TestInvalidUsernameorPassword(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { diff --git a/plugins/inputs/statsd/statsd_test.go b/plugins/inputs/statsd/statsd_test.go index fd3b49b92..4a129266d 100644 --- a/plugins/inputs/statsd/statsd_test.go +++ b/plugins/inputs/statsd/statsd_test.go @@ -1766,14 +1766,14 @@ func TestUdp(t *testing.T) { statsd := Statsd{ Log: testutil.Logger{}, Protocol: "udp", - ServiceAddress: "localhost:8125", + ServiceAddress: "localhost:14223", AllowedPendingMessages: 250000, } var acc testutil.Accumulator require.NoError(t, statsd.Start(&acc)) defer statsd.Stop() - conn, err := net.Dial("udp", "127.0.0.1:8125") + conn, err := net.Dial("udp", "127.0.0.1:14223") _, err = conn.Write([]byte("cpu.time_idle:42|c\n")) require.NoError(t, err) err = conn.Close() diff --git a/plugins/outputs/graphite/graphite_test.go b/plugins/outputs/graphite/graphite_test.go index 82aad0d7d..025ee23ec 100644 --- a/plugins/outputs/graphite/graphite_test.go +++ b/plugins/outputs/graphite/graphite_test.go @@ -18,7 +18,7 @@ import ( func TestGraphiteError(t *testing.T) { // Init plugin g := Graphite{ - Servers: []string{"127.0.0.1:2003", "127.0.0.1:12003"}, + Servers: []string{"127.0.0.1:12004", "127.0.0.1:12003"}, Prefix: "my.prefix", } // Init metrics @@ -48,7 +48,8 @@ func TestGraphiteOK(t *testing.T) { // Init plugin g := Graphite{ - Prefix: "my.prefix", + Prefix: "my.prefix", + Servers: []string{"localhost:12003"}, } // Init metrics @@ -109,6 +110,7 @@ func TestGraphiteOkWithSeparatorDot(t *testing.T) { g := Graphite{ Prefix: "my.prefix", GraphiteSeparator: ".", + Servers: []string{"localhost:12003"}, } // Init metrics @@ -169,6 +171,7 @@ func TestGraphiteOkWithSeparatorUnderscore(t *testing.T) { g := Graphite{ Prefix: "my.prefix", GraphiteSeparator: "_", + Servers: []string{"localhost:12003"}, } // Init metrics @@ -233,6 +236,7 @@ func TestGraphiteOKWithMultipleTemplates(t *testing.T) { "my_* host.measurement.tags.field", "measurement.tags.host.field", }, + Servers: []string{"localhost:12003"}, } // Init metrics @@ -293,6 +297,7 @@ func TestGraphiteOkWithTags(t *testing.T) { g := Graphite{ Prefix: "my.prefix", GraphiteTagSupport: true, + Servers: []string{"localhost:12003"}, } // Init metrics @@ -354,6 +359,7 @@ func TestGraphiteOkWithTagsAndSeparatorDot(t *testing.T) { Prefix: "my.prefix", GraphiteTagSupport: true, GraphiteSeparator: ".", + Servers: []string{"localhost:12003"}, } // Init metrics @@ -415,6 +421,7 @@ func TestGraphiteOkWithTagsAndSeparatorUnderscore(t *testing.T) { Prefix: "my_prefix", GraphiteTagSupport: true, GraphiteSeparator: "_", + Servers: []string{"localhost:12003"}, } // Init metrics @@ -465,7 +472,8 @@ func TestGraphiteOkWithTagsAndSeparatorUnderscore(t *testing.T) { } func TCPServer1(t *testing.T, wg *sync.WaitGroup) { - tcpServer, _ := net.Listen("tcp", "127.0.0.1:2003") + tcpServer, err := net.Listen("tcp", "127.0.0.1:12003") + require.NoError(t, err) go func() { defer wg.Done() conn, _ := (tcpServer).Accept() @@ -479,7 +487,7 @@ func TCPServer1(t *testing.T, wg *sync.WaitGroup) { } func TCPServer2(t *testing.T, wg *sync.WaitGroup) { - tcpServer, _ := net.Listen("tcp", "127.0.0.1:2003") + tcpServer, _ := net.Listen("tcp", "127.0.0.1:12003") go func() { defer wg.Done() conn2, _ := (tcpServer).Accept() @@ -495,7 +503,7 @@ func TCPServer2(t *testing.T, wg *sync.WaitGroup) { } func TCPServer1WithMultipleTemplates(t *testing.T, wg *sync.WaitGroup) { - tcpServer, _ := net.Listen("tcp", "127.0.0.1:2003") + tcpServer, _ := net.Listen("tcp", "127.0.0.1:12003") go func() { defer wg.Done() conn, _ := (tcpServer).Accept() @@ -509,7 +517,7 @@ func TCPServer1WithMultipleTemplates(t *testing.T, wg *sync.WaitGroup) { } func TCPServer2WithMultipleTemplates(t *testing.T, wg *sync.WaitGroup) { - tcpServer, _ := net.Listen("tcp", "127.0.0.1:2003") + tcpServer, _ := net.Listen("tcp", "127.0.0.1:12003") go func() { defer wg.Done() conn2, _ := (tcpServer).Accept() @@ -525,7 +533,7 @@ func TCPServer2WithMultipleTemplates(t *testing.T, wg *sync.WaitGroup) { } func TCPServer1WithTags(t *testing.T, wg *sync.WaitGroup) { - tcpServer, _ := net.Listen("tcp", "127.0.0.1:2003") + tcpServer, _ := net.Listen("tcp", "127.0.0.1:12003") go func() { defer wg.Done() conn, _ := (tcpServer).Accept() @@ -539,7 +547,7 @@ func TCPServer1WithTags(t *testing.T, wg *sync.WaitGroup) { } func TCPServer2WithTags(t *testing.T, wg *sync.WaitGroup) { - tcpServer, _ := net.Listen("tcp", "127.0.0.1:2003") + tcpServer, _ := net.Listen("tcp", "127.0.0.1:12003") go func() { defer wg.Done() conn2, _ := (tcpServer).Accept() @@ -555,7 +563,7 @@ func TCPServer2WithTags(t *testing.T, wg *sync.WaitGroup) { } func TCPServer1WithTagsSeparatorUnderscore(t *testing.T, wg *sync.WaitGroup) { - tcpServer, _ := net.Listen("tcp", "127.0.0.1:2003") + tcpServer, _ := net.Listen("tcp", "127.0.0.1:12003") go func() { defer wg.Done() conn, _ := (tcpServer).Accept() @@ -569,7 +577,7 @@ func TCPServer1WithTagsSeparatorUnderscore(t *testing.T, wg *sync.WaitGroup) { } func TCPServer2WithTagsSeparatorUnderscore(t *testing.T, wg *sync.WaitGroup) { - tcpServer, _ := net.Listen("tcp", "127.0.0.1:2003") + tcpServer, _ := net.Listen("tcp", "127.0.0.1:12003") go func() { defer wg.Done() conn2, _ := (tcpServer).Accept()