diff --git a/plugins/common/proxy/socks5_test.go b/plugins/common/proxy/socks5_test.go index 3bd7488047aac..9d1013a91b340 100644 --- a/plugins/common/proxy/socks5_test.go +++ b/plugins/common/proxy/socks5_test.go @@ -32,7 +32,11 @@ func TestSocks5ProxyConfigIntegration(t *testing.T) { }) require.NoError(t, err) - go func() { require.NoError(t, server.ListenAndServe("tcp", proxyAddress)) }() + go func() { + if err := server.ListenAndServe("tcp", proxyAddress); err != nil { + t.Error(err) + } + }() conf := Socks5ProxyConfig{ Socks5ProxyEnabled: true, diff --git a/plugins/common/shim/goshim_test.go b/plugins/common/shim/goshim_test.go index b123cc5addbcb..653de4bedadc1 100644 --- a/plugins/common/shim/goshim_test.go +++ b/plugins/common/shim/goshim_test.go @@ -50,8 +50,9 @@ func runErroringInputPlugin(t *testing.T, interval time.Duration, stdin io.Reade err := shim.AddInput(inp) require.NoError(t, err) go func() { - err := shim.Run(interval) - require.NoError(t, err) + if err := shim.Run(interval); err != nil { + t.Error(err) + } exited <- true }() return metricProcessed, exited diff --git a/plugins/common/shim/input_test.go b/plugins/common/shim/input_test.go index 0233c7d8f896a..8c2142823d5c5 100644 --- a/plugins/common/shim/input_test.go +++ b/plugins/common/shim/input_test.go @@ -47,8 +47,9 @@ func TestInputShimStdinSignalingWorks(t *testing.T) { err = stdinWriter.Close() require.NoError(t, err) go func() { - _, err = io.ReadAll(r) - require.NoError(t, err) + if _, err = io.ReadAll(r); err != nil { + t.Error(err) + } }() // check that it exits cleanly <-exited @@ -74,8 +75,9 @@ func runInputPlugin(t *testing.T, interval time.Duration, stdin io.Reader, stdou err := shim.AddInput(inp) require.NoError(t, err) go func() { - err := shim.Run(interval) - require.NoError(t, err) + if err := shim.Run(interval); err != nil { + t.Error(err) + } exited <- true }() return metricProcessed, exited diff --git a/plugins/common/shim/output_test.go b/plugins/common/shim/output_test.go index 4340ecf43e2b5..eaca4a7a7bfde 100644 --- a/plugins/common/shim/output_test.go +++ b/plugins/common/shim/output_test.go @@ -28,8 +28,9 @@ func TestOutputShim(t *testing.T) { wg.Add(1) go func() { - err := s.RunOutput() - require.NoError(t, err) + if err := s.RunOutput(); err != nil { + t.Error(err) + } wg.Done() }() diff --git a/plugins/common/shim/processor_test.go b/plugins/common/shim/processor_test.go index 195d725720b05..b8a476828c31e 100644 --- a/plugins/common/shim/processor_test.go +++ b/plugins/common/shim/processor_test.go @@ -47,8 +47,9 @@ func testSendAndReceive(t *testing.T, fieldKey string, fieldValue string) { wg.Add(1) go func() { - err := s.RunProcessor() - require.NoError(t, err) + if err := s.RunProcessor(); err != nil { + t.Error(err) + } wg.Done() }() @@ -88,8 +89,9 @@ func testSendAndReceive(t *testing.T, fieldKey string, fieldValue string) { require.True(t, ok) require.Equal(t, fieldValue, val2) go func() { - _, err = io.ReadAll(r) - require.NoError(t, err) + if _, err = io.ReadAll(r); err != nil { + t.Error(err) + } }() wg.Wait() } diff --git a/plugins/inputs/apcupsd/apcupsd_test.go b/plugins/inputs/apcupsd/apcupsd_test.go index 5ea9af55cd154..1ce26542d2419 100644 --- a/plugins/inputs/apcupsd/apcupsd_test.go +++ b/plugins/inputs/apcupsd/apcupsd_test.go @@ -1,6 +1,7 @@ package apcupsd import ( + "bytes" "context" "encoding/binary" "net" @@ -44,22 +45,34 @@ func listen(ctx context.Context, t *testing.T, out [][]byte) (string, error) { return } defer conn.Close() - require.NoError(t, conn.SetReadDeadline(time.Now().Add(time.Second))) + + if err = conn.SetReadDeadline(time.Now().Add(time.Second)); err != nil { + t.Error(err) + return + } in := make([]byte, 128) n, err := conn.Read(in) - require.NoError(t, err, "failed to read from connection") + if err != nil { + t.Errorf("Failed to read to connection: %v", err) + return + } status := []byte{0, 6, 's', 't', 'a', 't', 'u', 's'} want, got := status, in[:n] - require.Equal(t, want, got) + if !bytes.Equal(want, got) { + t.Errorf("expected %q, got %q", want, got) + return + } // Run against test function and append EOF to end of output bytes out = append(out, []byte{0, 0}) for _, o := range out { - _, err := conn.Write(o) - require.NoError(t, err, "failed to write to connection") + if _, err := conn.Write(o); err != nil { + t.Errorf("Failed to write to connection: %v", err) + return + } } }() } diff --git a/plugins/inputs/chrony/chrony_test.go b/plugins/inputs/chrony/chrony_test.go index e016c5cafe0f8..2e48312ab9e16 100644 --- a/plugins/inputs/chrony/chrony_test.go +++ b/plugins/inputs/chrony/chrony_test.go @@ -762,7 +762,7 @@ func (s *Server) serve(t *testing.T) { var header fbchrony.RequestHead data := bytes.NewBuffer(buf) if err := binary.Read(data, binary.BigEndian, &header); err != nil { - t.Logf("mock server: reading request header failed: %v", err) + t.Errorf("mock server: reading request header failed: %v", err) return } seqno := header.Sequence + 1 @@ -772,58 +772,79 @@ func (s *Server) serve(t *testing.T) { case 14: // sources _, err := s.conn.WriteTo(s.encodeSourcesReply(seqno), addr) if err != nil { - t.Logf("mock server [sources]: writing reply failed: %v", err) + t.Errorf("mock server [sources]: writing reply failed: %v", err) } else { t.Log("mock server [sources]: successfully wrote reply") } case 15: // source data var idx int32 - require.NoError(t, binary.Read(data, binary.BigEndian, &idx)) + if err = binary.Read(data, binary.BigEndian, &idx); err != nil { + t.Error(err) + return + } _, err = s.conn.WriteTo(s.encodeSourceDataReply(seqno, idx), addr) if err != nil { - t.Logf("mock server [source data]: writing reply failed: %v", err) + t.Errorf("mock server [source data]: writing reply failed: %v", err) } else { t.Log("mock server [source data]: successfully wrote reply") } case 33: // tracking _, err := s.conn.WriteTo(s.encodeTrackingReply(seqno), addr) if err != nil { - t.Logf("mock server [tracking]: writing reply failed: %v", err) + t.Errorf("mock server [tracking]: writing reply failed: %v", err) } else { t.Log("mock server [tracking]: successfully wrote reply") } case 34: // source stats var idx int32 - require.NoError(t, binary.Read(data, binary.BigEndian, &idx)) + if err = binary.Read(data, binary.BigEndian, &idx); err != nil { + t.Error(err) + return + } _, err = s.conn.WriteTo(s.encodeSourceStatsReply(seqno, idx), addr) if err != nil { - t.Logf("mock server [source stats]: writing reply failed: %v", err) + t.Errorf("mock server [source stats]: writing reply failed: %v", err) } else { t.Log("mock server [source stats]: successfully wrote reply") } case 44: // activity - _, err := s.conn.WriteTo(s.encodeActivityReply(seqno, t), addr) + payload, err := s.encodeActivityReply(seqno) if err != nil { - t.Logf("mock server [activity]: writing reply failed: %v", err) + t.Error(err) + return + } + + _, err = s.conn.WriteTo(payload, addr) + if err != nil { + t.Errorf("mock server [activity]: writing reply failed: %v", err) } else { t.Log("mock server [activity]: successfully wrote reply") } case 54: // server stats - _, err := s.conn.WriteTo(s.encodeServerStatsReply(seqno, t), addr) + payload, err := s.encodeServerStatsReply(seqno) + if err != nil { + t.Error(err) + return + } + + _, err = s.conn.WriteTo(payload, addr) if err != nil { - t.Logf("mock server [serverstats]: writing reply failed: %v", err) + t.Errorf("mock server [serverstats]: writing reply failed: %v", err) } else { t.Log("mock server [serverstats]: successfully wrote reply") } case 65: // source name buf := make([]byte, 20) _, err := data.Read(buf) - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } ip := decodeIP(buf) t.Logf("mock server [source name]: resolving %v", ip) _, err = s.conn.WriteTo(s.encodeSourceNameReply(seqno, ip), addr) if err != nil { - t.Logf("mock server [source name]: writing reply failed: %v", err) + t.Errorf("mock server [source name]: writing reply failed: %v", err) } else { t.Log("mock server [source name]: successfully wrote reply") } @@ -833,15 +854,17 @@ func (s *Server) serve(t *testing.T) { } } -func (s *Server) encodeActivityReply(sequence uint32, t *testing.T) []byte { +func (s *Server) encodeActivityReply(sequence uint32) ([]byte, error) { // Encode the header buf := encodeHeader(44, 12, 0, sequence) // activity request // Encode data b := bytes.NewBuffer(buf) - require.NoError(t, binary.Write(b, binary.BigEndian, s.ActivityInfo)) + if err := binary.Write(b, binary.BigEndian, s.ActivityInfo); err != nil { + return nil, err + } - return b.Bytes() + return b.Bytes(), nil } func (s *Server) encodeTrackingReply(sequence uint32) []byte { @@ -873,8 +896,10 @@ func (s *Server) encodeTrackingReply(sequence uint32) []byte { return buf } -func (s *Server) encodeServerStatsReply(sequence uint32, t *testing.T) []byte { +func (s *Server) encodeServerStatsReply(sequence uint32) ([]byte, error) { var b *bytes.Buffer + var err error + switch info := s.ServerStatInfo.(type) { case *fbchrony.ServerStats: // Encode the header @@ -882,24 +907,27 @@ func (s *Server) encodeServerStatsReply(sequence uint32, t *testing.T) []byte { // Encode data b = bytes.NewBuffer(buf) - require.NoError(t, binary.Write(b, binary.BigEndian, info)) + err = binary.Write(b, binary.BigEndian, info) case *fbchrony.ServerStats2: // Encode the header buf := encodeHeader(54, 22, 0, sequence) // activity request // Encode data b = bytes.NewBuffer(buf) - require.NoError(t, binary.Write(b, binary.BigEndian, info)) + err = binary.Write(b, binary.BigEndian, info) case *fbchrony.ServerStats3: // Encode the header buf := encodeHeader(54, 24, 0, sequence) // activity request // Encode data b = bytes.NewBuffer(buf) - require.NoError(t, binary.Write(b, binary.BigEndian, info)) + err = binary.Write(b, binary.BigEndian, info) } - return b.Bytes() + if err != nil { + return nil, err + } + return b.Bytes(), nil } func (s *Server) encodeSourcesReply(sequence uint32) []byte { diff --git a/plugins/inputs/dovecot/dovecot_test.go b/plugins/inputs/dovecot/dovecot_test.go index 9adf84ae1520e..19d98f65fa609 100644 --- a/plugins/inputs/dovecot/dovecot_test.go +++ b/plugins/inputs/dovecot/dovecot_test.go @@ -59,25 +59,38 @@ func TestDovecotIntegration(t *testing.T) { defer close(waitCh) la, err := net.ResolveUnixAddr("unix", addr) - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } l, err := net.ListenUnix("unix", la) - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } defer l.Close() defer os.Remove(addr) waitCh <- 0 conn, err := l.Accept() - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } defer conn.Close() readertp := textproto.NewReader(bufio.NewReader(conn)) - _, err = readertp.ReadLine() - require.NoError(t, err) + if _, err = readertp.ReadLine(); err != nil { + t.Error(err) + return + } buf := bytes.NewBufferString(sampleGlobal) - _, err = io.Copy(conn, buf) - require.NoError(t, err) + if _, err = io.Copy(conn, buf); err != nil { + t.Error(err) + return + } }() // Wait for server to start diff --git a/plugins/inputs/dpdk/dpdk_test.go b/plugins/inputs/dpdk/dpdk_test.go index 40d1d93f45289..60d65bd7d944d 100644 --- a/plugins/inputs/dpdk/dpdk_test.go +++ b/plugins/inputs/dpdk/dpdk_test.go @@ -907,13 +907,21 @@ func createMultipleSocketsForTest(t *testing.T, numSockets int, dirPath string) func simulateSocketResponse(socket net.Listener, t *testing.T) { conn, err := socket.Accept() - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } initMessage, err := json.Marshal(initMessage{MaxOutputLen: 1}) - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } - _, err = conn.Write(initMessage) - require.NoError(t, err) + if _, err = conn.Write(initMessage); err != nil { + t.Error(err) + return + } } func prepareGlob(path string) (*globpath.GlobPath, error) { diff --git a/plugins/inputs/execd/shim/shim_posix_test.go b/plugins/inputs/execd/shim/shim_posix_test.go index 310d50dc47782..0b25f1240ba8d 100644 --- a/plugins/inputs/execd/shim/shim_posix_test.go +++ b/plugins/inputs/execd/shim/shim_posix_test.go @@ -37,7 +37,11 @@ func TestShimUSR1SignalingWorks(t *testing.T) { return // test is done default: // test isn't done, keep going. - require.NoError(t, process.Signal(syscall.SIGUSR1)) + if err := process.Signal(syscall.SIGUSR1); err != nil { + t.Error(err) + metricProcessed <- false + return + } time.Sleep(200 * time.Millisecond) } } diff --git a/plugins/inputs/execd/shim/shim_test.go b/plugins/inputs/execd/shim/shim_test.go index 33aa87f6ec4ea..3095f10e62ef2 100644 --- a/plugins/inputs/execd/shim/shim_test.go +++ b/plugins/inputs/execd/shim/shim_test.go @@ -73,8 +73,9 @@ func runInputPlugin(t *testing.T, interval time.Duration, stdin io.Reader, stdou require.NoError(t, shim.AddInput(inp)) go func() { - err := shim.Run(interval) - require.NoError(t, err) + if err := shim.Run(interval); err != nil { + t.Error(err) + } exited <- true }() return metricProcessed, exited diff --git a/plugins/inputs/gnmi/gnmi_test.go b/plugins/inputs/gnmi/gnmi_test.go index 49b3d38999b64..3d32d9f679b0a 100644 --- a/plugins/inputs/gnmi/gnmi_test.go +++ b/plugins/inputs/gnmi/gnmi_test.go @@ -95,8 +95,9 @@ func TestWaitError(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - err := grpcServer.Serve(listener) - require.NoError(t, err) + if err := grpcServer.Serve(listener); err != nil { + t.Error(err) + } }() acc.WaitError(1) @@ -154,8 +155,9 @@ func TestUsernamePassword(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - err := grpcServer.Serve(listener) - require.NoError(t, err) + if err := grpcServer.Serve(listener); err != nil { + t.Error(err) + } }() acc.WaitError(1) @@ -1011,8 +1013,9 @@ func TestNotification(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - err := grpcServer.Serve(listener) - require.NoError(t, err) + if err := grpcServer.Serve(listener); err != nil { + t.Error(err) + } }() acc.Wait(len(tt.expected)) @@ -1063,8 +1066,9 @@ func TestRedial(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - err := grpcServer.Serve(listener) - require.NoError(t, err) + if err := grpcServer.Serve(listener); err != nil { + t.Error(err) + } }() var acc testutil.Accumulator @@ -1095,8 +1099,9 @@ func TestRedial(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - err := grpcServer.Serve(listener) - require.NoError(t, err) + if err := grpcServer.Serve(listener); err != nil { + t.Error(err) + } }() acc.Wait(4) @@ -1199,8 +1204,9 @@ func TestCases(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - err := grpcServer.Serve(listener) - require.NoError(t, err) + if err := grpcServer.Serve(listener); err != nil { + t.Error(err) + } }() var acc testutil.Accumulator diff --git a/plugins/inputs/hddtemp/go-hddtemp/hddtemp_test.go b/plugins/inputs/hddtemp/go-hddtemp/hddtemp_test.go index 41d513e4011e3..870a3df453421 100644 --- a/plugins/inputs/hddtemp/go-hddtemp/hddtemp_test.go +++ b/plugins/inputs/hddtemp/go-hddtemp/hddtemp_test.go @@ -80,11 +80,19 @@ func serve(t *testing.T, data []byte) net.Listener { go func(t *testing.T) { conn, err := l.Accept() - require.NoError(t, err) - - _, err = conn.Write(data) - require.NoError(t, err) - require.NoError(t, conn.Close()) + if err != nil { + t.Error(err) + return + } + + if _, err = conn.Write(data); err != nil { + t.Error(err) + return + } + if err = conn.Close(); err != nil { + t.Error(err) + return + } }(t) return l diff --git a/plugins/inputs/intel_dlb/intel_dlb_test.go b/plugins/inputs/intel_dlb/intel_dlb_test.go index 0b31bab3eb12f..a5bef4af72dac 100644 --- a/plugins/inputs/intel_dlb/intel_dlb_test.go +++ b/plugins/inputs/intel_dlb/intel_dlb_test.go @@ -935,7 +935,10 @@ func simulateResponse(mockConn *mocks.Conn, response string, readErr error) { func simulateSocketResponseForGather(socket net.Listener, t *testing.T) { conn, err := socket.Accept() - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } type initMessage struct { Version string `json:"version"` @@ -947,14 +950,21 @@ func simulateSocketResponseForGather(socket net.Listener, t *testing.T) { Pid: 1, MaxOutputLen: 1024, }) - require.NoError(t, err) - _, err = conn.Write(initMsg) - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } + + if _, err = conn.Write(initMsg); err != nil { + t.Error(err) + return + } - require.NoError(t, err) eventdevListWithSecondIndex := []string{"/eventdev/port_list", "/eventdev/queue_list"} - _, err = fmt.Fprintf(conn, `{%q: [0, 1]}`, eventdevListWithSecondIndex[0]) - require.NoError(t, err) + if _, err = fmt.Fprintf(conn, `{%q: [0, 1]}`, eventdevListWithSecondIndex[0]); err != nil { + t.Error(err) + return + } } func createSocketForTest(t *testing.T) (string, net.Listener) { diff --git a/plugins/inputs/kafka_consumer/kafka_consumer_test.go b/plugins/inputs/kafka_consumer/kafka_consumer_test.go index bbfc6ff38c8ac..76c9c5104f434 100644 --- a/plugins/inputs/kafka_consumer/kafka_consumer_test.go +++ b/plugins/inputs/kafka_consumer/kafka_consumer_test.go @@ -355,8 +355,14 @@ func TestConsumerGroupHandlerConsumeClaim(t *testing.T) { go func() { err := cg.ConsumeClaim(session, claim) - require.Error(t, err) - require.EqualValues(t, "context canceled", err.Error()) + if err == nil { + t.Error("An error was expected.") + return + } + if err.Error() != "context canceled" { + t.Errorf("Expected 'context canceled' error, got: %v", err) + return + } }() acc.Wait(1) diff --git a/plugins/inputs/net_response/net_response_test.go b/plugins/inputs/net_response/net_response_test.go index b70ebd4f3bfe4..bfb6c2ce803c5 100644 --- a/plugins/inputs/net_response/net_response_test.go +++ b/plugins/inputs/net_response/net_response_test.go @@ -267,32 +267,75 @@ func TestUDPOK1(t *testing.T) { func UDPServer(t *testing.T, wg *sync.WaitGroup) { defer wg.Done() udpAddr, err := net.ResolveUDPAddr("udp", "127.0.0.1:2004") - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } + conn, err := net.ListenUDP("udp", udpAddr) - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } + wg.Done() buf := make([]byte, 1024) _, remoteaddr, err := conn.ReadFromUDP(buf) - require.NoError(t, err) - _, err = conn.WriteToUDP(buf, remoteaddr) - require.NoError(t, err) - require.NoError(t, conn.Close()) + if err != nil { + t.Error(err) + return + } + + if _, err = conn.WriteToUDP(buf, remoteaddr); err != nil { + t.Error(err) + return + } + + if err = conn.Close(); err != nil { + t.Error(err) + return + } } func TCPServer(t *testing.T, wg *sync.WaitGroup) { defer wg.Done() tcpAddr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:2004") - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } + tcpServer, err := net.ListenTCP("tcp", tcpAddr) - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } + wg.Done() conn, err := tcpServer.AcceptTCP() - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } + buf := make([]byte, 1024) - _, err = conn.Read(buf) - require.NoError(t, err) - _, err = conn.Write(buf) - require.NoError(t, err) - require.NoError(t, conn.CloseWrite()) - require.NoError(t, tcpServer.Close()) + if _, err = conn.Read(buf); err != nil { + t.Error(err) + return + } + + if _, err = conn.Write(buf); err != nil { + t.Error(err) + return + } + + if err = conn.CloseWrite(); err != nil { + t.Error(err) + return + } + + if err = tcpServer.Close(); err != nil { + t.Error(err) + return + } } diff --git a/plugins/inputs/radius/radius_test.go b/plugins/inputs/radius/radius_test.go index 0eb02ea267a63..d9d3418868067 100644 --- a/plugins/inputs/radius/radius_test.go +++ b/plugins/inputs/radius/radius_test.go @@ -50,7 +50,8 @@ func TestRadiusLocal(t *testing.T) { go func() { if err := server.Serve(conn); err != nil { if !errors.Is(err, radius.ErrServerShutdown) { - require.NoError(t, err, "local radius server failed") + t.Errorf("Local radius server failed: %v", err) + return } } }() @@ -118,7 +119,8 @@ func TestRadiusNASIP(t *testing.T) { go func() { if err := server.Serve(conn); err != nil { if !errors.Is(err, radius.ErrServerShutdown) { - require.NoError(t, err, "local radius server failed") + t.Errorf("Local radius server failed: %v", err) + return } } }() diff --git a/plugins/inputs/statsd/statsd_test.go b/plugins/inputs/statsd/statsd_test.go index f76a8ded1fb9c..9ba0ccc96c4b3 100644 --- a/plugins/inputs/statsd/statsd_test.go +++ b/plugins/inputs/statsd/statsd_test.go @@ -202,8 +202,10 @@ func BenchmarkUDPThreads4(b *testing.B) { go func() { defer wg.Done() for i := 0; i < 1000; i++ { - _, err := conn.Write([]byte(testMsg)) - require.NoError(b, err) + if _, err := conn.Write([]byte(testMsg)); err != nil { + b.Error(err) + return + } } }() } @@ -239,8 +241,10 @@ func BenchmarkUDPThreads8(b *testing.B) { go func() { defer wg.Done() for i := 0; i < 1000; i++ { - _, err := conn.Write([]byte(testMsg)) - require.NoError(b, err) + if _, err := conn.Write([]byte(testMsg)); err != nil { + b.Error(err) + return + } } }() } @@ -276,8 +280,10 @@ func BenchmarkUDPThreads16(b *testing.B) { go func() { defer wg.Done() for i := 0; i < 1000; i++ { - _, err := conn.Write([]byte(testMsg)) - require.NoError(b, err) + if _, err := conn.Write([]byte(testMsg)); err != nil { + b.Error(err) + return + } } }() } diff --git a/plugins/inputs/teamspeak/teamspeak_test.go b/plugins/inputs/teamspeak/teamspeak_test.go index 4d56f5834282c..4612f3cc80940 100644 --- a/plugins/inputs/teamspeak/teamspeak_test.go +++ b/plugins/inputs/teamspeak/teamspeak_test.go @@ -89,34 +89,51 @@ func TestGather(t *testing.T) { func handleRequest(l net.Listener, t *testing.T) { c, err := l.Accept() - require.NoError(t, err, "Error accepting test connection") - _, err = c.Write([]byte("TS3\n\r" + welcome + "\n\r")) - require.NoError(t, err) + if err != nil { + t.Errorf("Error accepting test connection: %v", err) + return + } + + if _, err = c.Write([]byte("TS3\n\r" + welcome + "\n\r")); err != nil { + t.Error(err) + return + } + for { msg, _, err := bufio.NewReader(c).ReadLine() if err != nil { + t.Error(err) return } - r, exists := cmd[strings.Split(string(msg), " ")[0]] + r, exists := cmd[strings.Split(string(msg), " ")[0]] if exists { switch r { case "": - _, err = c.Write([]byte(ok + "\n\r")) - require.NoError(t, err) + if _, err = c.Write([]byte(ok + "\n\r")); err != nil { + t.Error(err) + return + } case "quit": - _, err = c.Write([]byte(ok + "\n\r")) - require.NoError(t, err) - err = c.Close() - require.NoError(t, err) + if _, err = c.Write([]byte(ok + "\n\r")); err != nil { + t.Error(err) + return + } + if err = c.Close(); err != nil { + t.Error(err) + } return default: - _, err = c.Write([]byte(r + "\n\r" + ok + "\n\r")) - require.NoError(t, err) + if _, err = c.Write([]byte(r + "\n\r" + ok + "\n\r")); err != nil { + t.Error(err) + return + } } } else { - _, err = c.Write([]byte(errorMsg + "\n\r")) - require.NoError(t, err) + if _, err = c.Write([]byte(errorMsg + "\n\r")); err != nil { + t.Error(err) + return + } } } } diff --git a/plugins/inputs/x509_cert/x509_cert_test.go b/plugins/inputs/x509_cert/x509_cert_test.go index fbe35dfc94dcb..bb4f72cc14d07 100644 --- a/plugins/inputs/x509_cert/x509_cert_test.go +++ b/plugins/inputs/x509_cert/x509_cert_test.go @@ -89,18 +89,25 @@ func TestGatherRemoteIntegration(t *testing.T) { go func() { sconn, err := ln.Accept() - require.NoError(t, err) + if err != nil { + t.Error(err) + return + } + if test.close { sconn.Close() } serverConfig := cfg.Clone() - srv := tls.Server(sconn, serverConfig) if test.noshake { srv.Close() } - require.NoError(t, srv.Handshake()) + + if err = srv.Handshake(); err != nil { + t.Error(err) + return + } }() if test.server == "" { @@ -318,8 +325,9 @@ func TestGatherUDPCertIntegration(t *testing.T) { defer listener.Close() go func() { - _, err := listener.Accept() - require.NoError(t, err) + if _, err := listener.Accept(); err != nil { + t.Error(err) + } }() m := &X509Cert{