fix some annoying tests due to ports in use

This commit is contained in:
Steven Soroka 2021-01-08 17:30:43 -05:00
parent f31203b4b2
commit 9814d3d84d
3 changed files with 20 additions and 30 deletions

View File

@ -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) {

View File

@ -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()

View File

@ -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()