diff --git a/plugins/inputs/fluentd/fluentd_test.go b/plugins/inputs/fluentd/fluentd_test.go index a822c763f1402..1e6110ffac178 100644 --- a/plugins/inputs/fluentd/fluentd_test.go +++ b/plugins/inputs/fluentd/fluentd_test.go @@ -131,7 +131,8 @@ func Test_Gather(t *testing.T) { require.NoError(t, err) require.NotNil(t, requestURL) - ts.Listener, _ = net.Listen("tcp", fmt.Sprintf("%s:%s", requestURL.Hostname(), requestURL.Port())) + ts.Listener, err = net.Listen("tcp", fmt.Sprintf("%s:%s", requestURL.Hostname(), requestURL.Port())) + require.NoError(t, err) ts.Start() diff --git a/plugins/inputs/logstash/logstash_test.go b/plugins/inputs/logstash/logstash_test.go index 089824c58767f..6059d4eac9b1b 100644 --- a/plugins/inputs/logstash/logstash_test.go +++ b/plugins/inputs/logstash/logstash_test.go @@ -32,7 +32,8 @@ func Test_Logstash5GatherProcessStats(test *testing.T) { })) requestURL, err := url.Parse(logstashTest.URL) require.NoErrorf(test, err, "Can't connect to: %s", logstashTest.URL) - fakeServer.Listener, _ = net.Listen("tcp", fmt.Sprintf("%s:%s", requestURL.Hostname(), requestURL.Port())) + fakeServer.Listener, err = net.Listen("tcp", fmt.Sprintf("%s:%s", requestURL.Hostname(), requestURL.Port())) + require.NoError(test, err) fakeServer.Start() defer fakeServer.Close() @@ -76,7 +77,8 @@ func Test_Logstash6GatherProcessStats(test *testing.T) { })) requestURL, err := url.Parse(logstashTest.URL) require.NoErrorf(test, err, "Can't connect to: %s", logstashTest.URL) - fakeServer.Listener, _ = net.Listen("tcp", fmt.Sprintf("%s:%s", requestURL.Hostname(), requestURL.Port())) + fakeServer.Listener, err = net.Listen("tcp", fmt.Sprintf("%s:%s", requestURL.Hostname(), requestURL.Port())) + require.NoError(test, err) fakeServer.Start() defer fakeServer.Close() @@ -121,7 +123,8 @@ func Test_Logstash5GatherPipelineStats(test *testing.T) { })) requestURL, err := url.Parse(logstashTest.URL) require.NoErrorf(test, err, "Can't connect to: %s", logstashTest.URL) - fakeServer.Listener, _ = net.Listen("tcp", fmt.Sprintf("%s:%s", requestURL.Hostname(), requestURL.Port())) + fakeServer.Listener, err = net.Listen("tcp", fmt.Sprintf("%s:%s", requestURL.Hostname(), requestURL.Port())) + require.NoError(test, err) fakeServer.Start() defer fakeServer.Close() @@ -218,7 +221,8 @@ func Test_Logstash6GatherPipelinesStats(test *testing.T) { })) requestURL, err := url.Parse(logstashTest.URL) require.NoErrorf(test, err, "Can't connect to: %s", logstashTest.URL) - fakeServer.Listener, _ = net.Listen("tcp", fmt.Sprintf("%s:%s", requestURL.Hostname(), requestURL.Port())) + fakeServer.Listener, err = net.Listen("tcp", fmt.Sprintf("%s:%s", requestURL.Hostname(), requestURL.Port())) + require.NoError(test, err) fakeServer.Start() defer fakeServer.Close() @@ -541,7 +545,8 @@ func Test_Logstash5GatherJVMStats(test *testing.T) { })) requestURL, err := url.Parse(logstashTest.URL) require.NoErrorf(test, err, "Can't connect to: %s", logstashTest.URL) - fakeServer.Listener, _ = net.Listen("tcp", fmt.Sprintf("%s:%s", requestURL.Hostname(), requestURL.Port())) + fakeServer.Listener, err = net.Listen("tcp", fmt.Sprintf("%s:%s", requestURL.Hostname(), requestURL.Port())) + require.NoError(test, err) fakeServer.Start() defer fakeServer.Close() @@ -604,7 +609,8 @@ func Test_Logstash6GatherJVMStats(test *testing.T) { })) requestURL, err := url.Parse(logstashTest.URL) require.NoErrorf(test, err, "Can't connect to: %s", logstashTest.URL) - fakeServer.Listener, _ = net.Listen("tcp", fmt.Sprintf("%s:%s", requestURL.Hostname(), requestURL.Port())) + fakeServer.Listener, err = net.Listen("tcp", fmt.Sprintf("%s:%s", requestURL.Hostname(), requestURL.Port())) + require.NoError(test, err) fakeServer.Start() defer fakeServer.Close() @@ -671,7 +677,8 @@ func Test_Logstash7GatherPipelinesQueueStats(test *testing.T) { if err != nil { test.Logf("Can't connect to: %s", logstashTest.URL) } - fakeServer.Listener, _ = net.Listen("tcp", fmt.Sprintf("%s:%s", requestURL.Hostname(), requestURL.Port())) + fakeServer.Listener, err = net.Listen("tcp", fmt.Sprintf("%s:%s", requestURL.Hostname(), requestURL.Port())) + require.NoError(test, err) fakeServer.Start() defer fakeServer.Close() diff --git a/plugins/inputs/net_response/net_response_test.go b/plugins/inputs/net_response/net_response_test.go index 83b23e11b1688..6a021d14ad2eb 100644 --- a/plugins/inputs/net_response/net_response_test.go +++ b/plugins/inputs/net_response/net_response_test.go @@ -265,24 +265,29 @@ func TestUDPOK1(t *testing.T) { func UDPServer(t *testing.T, wg *sync.WaitGroup) { defer wg.Done() - udpAddr, _ := net.ResolveUDPAddr("udp", "127.0.0.1:2004") - conn, _ := net.ListenUDP("udp", udpAddr) + udpAddr, err := net.ResolveUDPAddr("udp", "127.0.0.1:2004") + require.NoError(t, err) + conn, err := net.ListenUDP("udp", udpAddr) + require.NoError(t, err) wg.Done() buf := make([]byte, 1024) _, remoteaddr, _ := conn.ReadFromUDP(buf) - _, err := conn.WriteToUDP(buf, remoteaddr) + _, err = conn.WriteToUDP(buf, remoteaddr) require.NoError(t, err) require.NoError(t, conn.Close()) } func TCPServer(t *testing.T, wg *sync.WaitGroup) { defer wg.Done() - tcpAddr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:2004") - tcpServer, _ := net.ListenTCP("tcp", tcpAddr) + tcpAddr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:2004") + require.NoError(t, err) + tcpServer, err := net.ListenTCP("tcp", tcpAddr) + require.NoError(t, err) wg.Done() - conn, _ := tcpServer.AcceptTCP() + conn, err := tcpServer.AcceptTCP() + require.NoError(t, err) buf := make([]byte, 1024) - _, err := conn.Read(buf) + _, err = conn.Read(buf) require.NoError(t, err) _, err = conn.Write(buf) require.NoError(t, err) diff --git a/plugins/inputs/snmp/snmp_test.go b/plugins/inputs/snmp/snmp_test.go index b944e0ddbb376..25346c1259be5 100644 --- a/plugins/inputs/snmp/snmp_test.go +++ b/plugins/inputs/snmp/snmp_test.go @@ -310,8 +310,14 @@ func TestGetSNMPConnectionTCP(t *testing.T) { func stubTCPServer(wg *sync.WaitGroup) { defer wg.Done() - tcpAddr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:56789") - tcpServer, _ := net.ListenTCP("tcp", tcpAddr) + tcpAddr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:56789") + if err != nil { + fmt.Print(err) + } + tcpServer, err := net.ListenTCP("tcp", tcpAddr) + if err != nil { + fmt.Print(err) + } defer tcpServer.Close() wg.Done() conn, _ := tcpServer.AcceptTCP() diff --git a/plugins/outputs/graphite/graphite_test.go b/plugins/outputs/graphite/graphite_test.go index 7f96cb57ce538..d1bde0f48bd66 100644 --- a/plugins/outputs/graphite/graphite_test.go +++ b/plugins/outputs/graphite/graphite_test.go @@ -495,7 +495,8 @@ func TCPServer1(t *testing.T, wg *sync.WaitGroup) { } func TCPServer2(t *testing.T, wg *sync.WaitGroup) { - tcpServer, _ := net.Listen("tcp", "127.0.0.1:12003") + tcpServer, err := net.Listen("tcp", "127.0.0.1:12003") + require.NoError(t, err) go func() { defer wg.Done() conn2, _ := (tcpServer).Accept() @@ -511,7 +512,8 @@ func TCPServer2(t *testing.T, wg *sync.WaitGroup) { } func TCPServer1WithMultipleTemplates(t *testing.T, wg *sync.WaitGroup) { - tcpServer, _ := net.Listen("tcp", "127.0.0.1:12003") + tcpServer, err := net.Listen("tcp", "127.0.0.1:12003") + require.NoError(t, err) go func() { defer wg.Done() conn, _ := (tcpServer).Accept() @@ -525,7 +527,8 @@ func TCPServer1WithMultipleTemplates(t *testing.T, wg *sync.WaitGroup) { } func TCPServer2WithMultipleTemplates(t *testing.T, wg *sync.WaitGroup) { - tcpServer, _ := net.Listen("tcp", "127.0.0.1:12003") + tcpServer, err := net.Listen("tcp", "127.0.0.1:12003") + require.NoError(t, err) go func() { defer wg.Done() conn2, _ := (tcpServer).Accept() @@ -541,7 +544,8 @@ func TCPServer2WithMultipleTemplates(t *testing.T, wg *sync.WaitGroup) { } func TCPServer1WithTags(t *testing.T, wg *sync.WaitGroup) { - tcpServer, _ := net.Listen("tcp", "127.0.0.1:12003") + tcpServer, err := net.Listen("tcp", "127.0.0.1:12003") + require.NoError(t, err) go func() { defer wg.Done() conn, _ := (tcpServer).Accept() @@ -555,7 +559,8 @@ func TCPServer1WithTags(t *testing.T, wg *sync.WaitGroup) { } func TCPServer2WithTags(t *testing.T, wg *sync.WaitGroup) { - tcpServer, _ := net.Listen("tcp", "127.0.0.1:12003") + tcpServer, err := net.Listen("tcp", "127.0.0.1:12003") + require.NoError(t, err) go func() { defer wg.Done() conn2, _ := (tcpServer).Accept() @@ -571,7 +576,8 @@ func TCPServer2WithTags(t *testing.T, wg *sync.WaitGroup) { } func TCPServer1WithTagsSeparatorUnderscore(t *testing.T, wg *sync.WaitGroup) { - tcpServer, _ := net.Listen("tcp", "127.0.0.1:12003") + tcpServer, err := net.Listen("tcp", "127.0.0.1:12003") + require.NoError(t, err) go func() { defer wg.Done() conn, _ := (tcpServer).Accept() @@ -585,7 +591,8 @@ func TCPServer1WithTagsSeparatorUnderscore(t *testing.T, wg *sync.WaitGroup) { } func TCPServer2WithTagsSeparatorUnderscore(t *testing.T, wg *sync.WaitGroup) { - tcpServer, _ := net.Listen("tcp", "127.0.0.1:12003") + tcpServer, err := net.Listen("tcp", "127.0.0.1:12003") + require.NoError(t, err) go func() { defer wg.Done() conn2, _ := (tcpServer).Accept() diff --git a/plugins/outputs/instrumental/instrumental_test.go b/plugins/outputs/instrumental/instrumental_test.go index b55c6b33db9ee..54b3e0b67495a 100644 --- a/plugins/outputs/instrumental/instrumental_test.go +++ b/plugins/outputs/instrumental/instrumental_test.go @@ -79,7 +79,9 @@ func TestWrite(t *testing.T) { } func TCPServer(t *testing.T, wg *sync.WaitGroup) { - tcpServer, _ := net.Listen("tcp", "127.0.0.1:8000") + tcpServer, err := net.Listen("tcp", "127.0.0.1:8000") + require.NoError(t, err) + go func() { defer wg.Done() conn, _ := tcpServer.Accept()