diff --git a/comp/core/telemetry/telemetryimpl/prom_counter_test.go b/comp/core/telemetry/telemetryimpl/prom_counter_test.go index acc37a706514..4dcbf0c0f227 100644 --- a/comp/core/telemetry/telemetryimpl/prom_counter_test.go +++ b/comp/core/telemetry/telemetryimpl/prom_counter_test.go @@ -10,6 +10,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestPromCounterInitializer(t *testing.T) { @@ -41,18 +42,12 @@ func TestPromCounterInitializer(t *testing.T) { counter.InitializeToZero("mycheck", "mystate") endMetrics, err := promTelemetry.Gather() - if !assert.NoError(t, err) { - return - } + require.NoError(t, err) - if !assert.Equal(t, len(endMetrics), 1) { - return - } + require.Len(t, endMetrics, 1) metricFamily := endMetrics[0] - if !assert.Equal(t, len(metricFamily.GetMetric()), 1) { - return - } + require.Len(t, metricFamily.GetMetric(), 1) assert.Equal(t, metricFamily.GetName(), "subsystem_test") diff --git a/comp/core/telemetry/telemetryimpl/telemetry_test.go b/comp/core/telemetry/telemetryimpl/telemetry_test.go index 0f552a7832a2..02969912e0ba 100644 --- a/comp/core/telemetry/telemetryimpl/telemetry_test.go +++ b/comp/core/telemetry/telemetryimpl/telemetry_test.go @@ -24,13 +24,9 @@ func TestCounterInitializer(t *testing.T) { counter.InitializeToZero("mycheck", "mystate") startMetrics, err := telemetry.GetRegistry().Gather() - if !assert.NoError(t, err) { - return - } + require.NoError(t, err) - if !assert.Equal(t, len(startMetrics), 1) { - return - } + require.Equal(t, len(startMetrics), 1) metrics, err := telemetry.GetCountMetric("subsystem", "test") assert.NoError(t, err) diff --git a/comp/core/workloadmeta/collectors/internal/process/process_collector_test.go b/comp/core/workloadmeta/collectors/internal/process/process_collector_test.go index 212e2f337180..6ce80fc3db65 100644 --- a/comp/core/workloadmeta/collectors/internal/process/process_collector_test.go +++ b/comp/core/workloadmeta/collectors/internal/process/process_collector_test.go @@ -18,6 +18,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" @@ -692,9 +693,8 @@ func TestProcessDifferentCmdline(t *testing.T) { // Wait for first collection to complete assert.EventuallyWithT(t, func(cT *assert.CollectT) { actualProc, err := c.mockStore.GetProcess(pid) - if !assert.NoError(cT, err) || !assert.NotNil(cT, actualProc) { - return - } + require.NoError(cT, err) + require.NotNil(cT, actualProc) assert.Equal(cT, []string{"bash"}, actualProc.Cmdline) }, time.Second, time.Millisecond*100) @@ -704,9 +704,8 @@ func TestProcessDifferentCmdline(t *testing.T) { // After exec, the store should have htop, not bash assert.EventuallyWithT(t, func(cT *assert.CollectT) { actualProc, err := c.mockStore.GetProcess(pid) - if !assert.NoError(cT, err) || !assert.NotNil(cT, actualProc) { - return - } + require.NoError(cT, err) + require.NotNil(cT, actualProc) // Critical assertion: cmdline should be updated to htop after exec assert.Equal(cT, []string{"htop"}, actualProc.Cmdline, "Process cmdline should be updated after exec") assert.Equal(cT, "htop", actualProc.Name, "Process name should be updated after exec") diff --git a/pkg/collector/check/stats/stats_test.go b/pkg/collector/check/stats/stats_test.go index fd2fa4d0e15c..6d378ad736c3 100644 --- a/pkg/collector/check/stats/stats_test.go +++ b/pkg/collector/check/stats/stats_test.go @@ -12,6 +12,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/DataDog/datadog-agent/comp/core/telemetry/telemetryimpl" healthplatformmock "github.com/DataDog/datadog-agent/comp/healthplatform/mock" @@ -95,9 +96,7 @@ func TestNewStatsStateTelemetryInitialized(t *testing.T) { NewStats(newMockCheck(), healthplatformmock.Mock(t)) tlmData, err := getTelemetryData() - if !assert.NoError(t, err) { - return - } + require.NoError(t, err) assert.Contains( t, diff --git a/pkg/collector/corechecks/gpu/integrationtests/check_test.go b/pkg/collector/corechecks/gpu/integrationtests/check_test.go index 1ea4646350c3..65ca3018d064 100644 --- a/pkg/collector/corechecks/gpu/integrationtests/check_test.go +++ b/pkg/collector/corechecks/gpu/integrationtests/check_test.go @@ -82,9 +82,8 @@ func assertMetricCase(t *testing.T, metricsByName map[string][]mock.Call, tc met t.Helper() calls, ok := metricsByName[tc.name] - if !assert.True(t, ok, "%s metric should be present", tc.name) || !assert.NotEmpty(t, calls, "No calls found for metric %s", tc.name) { - return - } + require.True(t, ok, "%s metric should be present", tc.name) + require.NotEmpty(t, calls, "No calls found for metric %s", tc.name) for _, call := range calls { value := call.Arguments[1].(float64) diff --git a/pkg/compliance/dbconfig/loader_test.go b/pkg/compliance/dbconfig/loader_test.go index 40cef04fa794..7e34105767f7 100644 --- a/pkg/compliance/dbconfig/loader_test.go +++ b/pkg/compliance/dbconfig/loader_test.go @@ -20,6 +20,7 @@ import ( "github.com/DataDog/datadog-agent/pkg/compliance/types" "github.com/shirou/gopsutil/v4/process" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestDBConfLoader(t *testing.T) { @@ -599,9 +600,7 @@ include_dir 'conf.d' defer stop() c, ok := LoadPostgreSQLConfig(context.Background(), hostroot, proc) - if !assert.True(t, ok) { - return - } + require.True(t, ok) configData := c.ConfigData.(map[string]string) assert.Equal(t, "100", configData["max_connections"]) @@ -665,9 +664,7 @@ work_mem = 16MB c, ok := LoadPostgreSQLConfig(context.Background(), hostroot, proc) assert.True(t, ok) - if !assert.NotNil(t, c) { - return - } + require.NotNil(t, c) configData := c.ConfigData.(map[string]string) assert.Equal(t, "200", configData["max_connections"]) @@ -698,9 +695,7 @@ include 'circular.conf' c, ok := LoadPostgreSQLConfig(context.Background(), hostroot, proc) assert.True(t, ok) - if !assert.NotNil(t, c) { - return - } + require.NotNil(t, c) // Should not crash, circular protection should kick in configData := c.ConfigData.(map[string]string) assert.Equal(t, "100", configData["max_connections"]) diff --git a/pkg/dyninst/end_to_end_test.go b/pkg/dyninst/end_to_end_test.go index a296ad903981..0860f9f3d4a4 100644 --- a/pkg/dyninst/end_to_end_test.go +++ b/pkg/dyninst/end_to_end_test.go @@ -306,14 +306,12 @@ func runE2ETest(t *testing.T, cfg e2eTestConfig) { makeTargetStatus(uploader.StatusEmitting, expectedProbeIDs...), ) - assertModuleStats := func(t assert.TestingT, expected actuator.Metrics) { + assertModuleStats := func(t require.TestingT, expected actuator.Metrics) { stats := ts.module.GetStats()["actuator"].(map[string]any) exp := expected.AsStats() gotKeys := slices.Sorted(maps.Keys(stats)) expectedKeys := slices.Sorted(maps.Keys(exp)) - if !assert.Equal(t, gotKeys, expectedKeys) { - return - } + require.Equal(t, gotKeys, expectedKeys) for _, key := range gotKeys { assert.Equal(t, exp[key], stats[key], "key %s", key) } diff --git a/pkg/dyninst/missing_type_recompilation_test.go b/pkg/dyninst/missing_type_recompilation_test.go index 69223d96ab1a..8203b9dae555 100644 --- a/pkg/dyninst/missing_type_recompilation_test.go +++ b/pkg/dyninst/missing_type_recompilation_test.go @@ -177,9 +177,7 @@ func TestMissingTypeRecompilation(t *testing.T) { require.EventuallyWithT(t, func(c *assert.CollectT) { stats := m.GetStats() actuatorStats, ok := stats["actuator"].(map[string]any) - if !assert.True(c, ok, "actuator stats missing") { - return - } + require.True(c, ok, "actuator stats missing") assert.Equal(c, uint64(0), actuatorStats["numPrograms"], "expected numPrograms == 0 after cleanup") assert.Equal(c, uint64(0), actuatorStats["numProcesses"], diff --git a/pkg/dyninst/procsubscribe/procscan/proc_stat_reader_test.go b/pkg/dyninst/procsubscribe/procscan/proc_stat_reader_test.go index 6ca45dde228f..8bd7262cc92d 100644 --- a/pkg/dyninst/procsubscribe/procscan/proc_stat_reader_test.go +++ b/pkg/dyninst/procsubscribe/procscan/proc_stat_reader_test.go @@ -19,7 +19,6 @@ import ( "strings" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -95,28 +94,18 @@ func testCases(t testing.TB) iter.Seq[testCase] { filename := filepath.Base(entry) name := strings.TrimSuffix(filename, ".txt") expected, ok := expectedValues[name] - if !assert.True(t, ok, - "test file %s found but no expected values defined", name, - ) { - return - } + require.True(t, ok, + "test file %s found but no expected values defined", name) delete(expectedValues, name) data, err := testdataFS.ReadFile(entry) - if !assert.NoError(t, err, "failed to read test data") { - return - } + require.NoError(t, err, "failed to read test data") procRoot := filepath.Join(tempDir, name, "proc") pidDir := filepath.Join(procRoot, strconv.FormatInt(int64(expected.pid), 10)) - if !assert.NoError(t, os.MkdirAll(pidDir, 0o755)) { - return - } + require.NoError(t, os.MkdirAll(pidDir, 0o755)) statPath := filepath.Join(pidDir, "stat") - if !assert.NoError( + require.NoError( t, - os.WriteFile(statPath, data, 0o644), - ) { - return - } + os.WriteFile(statPath, data, 0o644)) if !yield(testCase{ name: name, expected: expected, diff --git a/pkg/fleet/installer/setup/config/write_test.go b/pkg/fleet/installer/setup/config/write_test.go index 320c48054baa..c3894e3ac4d2 100644 --- a/pkg/fleet/installer/setup/config/write_test.go +++ b/pkg/fleet/installer/setup/config/write_test.go @@ -13,6 +13,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "golang.org/x/text/encoding" "golang.org/x/text/encoding/unicode" ) @@ -362,9 +363,7 @@ api_key: newkey // The config file may be UTF-16 on Windows t.Run(tc.name+" (UTF-16)", func(t *testing.T) { encoded, err := unicode.UTF16(unicode.LittleEndian, unicode.ExpectBOM).NewEncoder().String(tc.initialYAML) - if !assert.NoError(t, err) { - return - } + require.NoError(t, err) tc.initialYAML = encoded runWriteConfigTestCase(t, tc) }) @@ -425,14 +424,10 @@ func TestEnsureUTF8(t *testing.T) { for _, e := range encodings { // encode input to new encoding encoded, err := e.NewEncoder().Bytes(input) - if !assert.NoError(t, err) { - return - } + require.NoError(t, err) // convert it back to UTF-8 output, err := ensureUTF8(encoded) - if !assert.NoError(t, err) { - return - } + require.NoError(t, err) assert.Equal(t, input, output) // assert output does not contain BOM assert.False(t, bytes.HasPrefix(output, []byte{0xFF, 0xFE}), "output should not have UTF-16LE BOM") diff --git a/pkg/network/tracer/tracer_linux_test.go b/pkg/network/tracer/tracer_linux_test.go index ed5bc7f2182c..deec3cdd61a0 100644 --- a/pkg/network/tracer/tracer_linux_test.go +++ b/pkg/network/tracer/tracer_linux_test.go @@ -122,9 +122,7 @@ func (s *TracerSuite) TestTCPRemoveEntries() { conns, cleanup := getConnections(ct, tr) defer cleanup() conn, ok := findConnection(c2.LocalAddr(), c2.RemoteAddr(), conns) - if !assert.True(ct, ok) { - return - } + require.True(ct, ok) assert.Equal(ct, clientMessageSize, int(conn.Monotonic.SentBytes)) assert.Equal(ct, 0, int(conn.Monotonic.RecvBytes)) assert.Equal(ct, 0, int(conn.Monotonic.Retransmits)) @@ -324,9 +322,7 @@ func (s *TracerSuite) TestTCPRTT() { allConnections, cleanup := getConnections(ct, tr) defer cleanup() conn, ok := findConnection(c.LocalAddr(), c.RemoteAddr(), allConnections) - if !assert.True(ct, ok) { - return - } + require.True(ct, ok) if cfg.EnableEbpfless { timeoutUs := uint32((10 * time.Second).Microseconds()) @@ -493,18 +489,14 @@ func (s *TracerSuite) TestConntrackExpiration() { var conn *network.ConnectionStats require.EventuallyWithT(t, func(collect *assert.CollectT) { _, err = c.Write([]byte("ping\n")) - if !assert.NoError(collect, err, "error sending data to server") { - return - } + require.NoError(collect, err, "error sending data to server") connections, cleanup := getConnections(collect, tr) defer cleanup() t.Log(connections) // for debugging failures var ok bool conn, ok = findConnection(c.LocalAddr(), c.RemoteAddr(), connections) - if !assert.True(collect, ok, "connection not found") { - return - } + require.True(collect, ok, "connection not found") assert.NotNil(collect, tr.conntracker.GetTranslationForConn(&conn.ConnectionTuple), "connection does not have NAT translation") }, 3*time.Second, 100*time.Millisecond, "failed to find connection translation") @@ -662,9 +654,7 @@ func (s *TracerSuite) TestUnconnectedUDPSendIPv6() { } return cs.DPort == uint16(remoteAddr.Port) }) - if !assert.Len(ct, outgoing, 1) { - return - } + require.Len(ct, outgoing, 1) assert.Equal(ct, remoteAddr.IP.String(), outgoing[0].Dest.String()) assert.Equal(ct, bytesSent, int(outgoing[0].Monotonic.SentBytes)) }, 3*time.Second, 100*time.Millisecond) @@ -2079,10 +2069,8 @@ func (s *TracerSuite) TestBlockingReadCounts() { return true }) - if !assert.NoError(collect, err, "error reading from connection") || - !assert.NoError(collect, readErr, "error from raw conn") { - return - } + require.NoError(collect, err, "error reading from connection") + require.NoError(collect, readErr, "error from raw conn") read += n t.Logf("read %d", read) @@ -2150,9 +2138,7 @@ func (s *TracerSuite) TestPreexistingConnectionDirection() { require.NotNil(collect, outgoing) require.NotNil(collect, incoming) - if !assert.True(collect, incoming != nil && outgoing != nil) { - return - } + require.True(collect, incoming != nil && outgoing != nil) m := outgoing.Monotonic // skip byte counts in ebpfless: for ebpfless pre-existing connections, @@ -3328,9 +3314,7 @@ func (s *TracerSuite) TestTCPRetransmitSyncOnClose() { defer cleanup() conn, ok := findConnection(c.LocalAddr(), c.RemoteAddr(), conns) - if !assert.True(ct, ok, "connection not found") { - return - } + require.True(ct, ok, "connection not found") // We expect retransmits > 0 assert.Greater(ct, int(conn.Monotonic.Retransmits), 0, "should have retransmits") diff --git a/pkg/network/tracer/tracer_test.go b/pkg/network/tracer/tracer_test.go index 40b139fafea7..0d2cb3da4d50 100644 --- a/pkg/network/tracer/tracer_test.go +++ b/pkg/network/tracer/tracer_test.go @@ -1052,24 +1052,16 @@ func testDNSStats(t *testing.T, tr *Tracer, domain string, success, failure, tim require.EventuallyWithT(t, func(c *assert.CollectT) { dnsClient := new(dns.Client) dnsConn, err := dnsClient.Dial(dnsServerAddr.String()) - if !assert.NoError(c, err) { - return - } + require.NoError(c, err) dnsClientAddr := dnsConn.LocalAddr().(*net.UDPAddr) _, _, err = dnsClient.ExchangeWithConn(queryMsg, dnsConn) if timeout == 0 { - if !assert.NoError(c, err, "unexpected error making DNS request") { - return - } + require.NoError(c, err, "unexpected error making DNS request") } else { - if !assert.Error(c, err) { - return - } + require.Error(c, err) } _ = dnsConn.Close() - if !assert.NoError(c, tr.reverseDNS.WaitForDomain(domain)) { - return - } + require.NoError(c, tr.reverseDNS.WaitForDomain(domain)) // Iterate through active connections until we find connection created above, and confirm send + recv counts connections, cleanup := getConnections(c, tr) @@ -1079,17 +1071,11 @@ func testDNSStats(t *testing.T, tr *Tracer, domain string, success, failure, tim return } - if !assert.Equal(c, queryMsg.Len(), int(conn.Monotonic.SentBytes)) { - return - } + require.Equal(c, queryMsg.Len(), int(conn.Monotonic.SentBytes)) if !tr.config.EnableEbpfless { - if !assert.Equal(c, os.Getpid(), int(conn.Pid)) { - return - } - } - if !assert.Equal(c, dnsServerAddr.Port, int(conn.DPort)) { - return + require.Equal(c, os.Getpid(), int(conn.Pid)) } + require.Equal(c, dnsServerAddr.Port, int(conn.DPort)) var total uint32 var successfulResponses uint32 @@ -1106,15 +1092,9 @@ func testDNSStats(t *testing.T, tr *Tracer, domain string, success, failure, tim failedResponses := total - successfulResponses // DNS Stats - if !assert.Equal(c, uint32(success), successfulResponses, "expected %d successful responses but got %d", success, successfulResponses) { - return - } - if !assert.Equal(c, uint32(failure), failedResponses) { - return - } - if !assert.Equal(c, uint32(timeout), timeouts, "expected %d timeouts but got %d", timeout, timeouts) { - return - } + require.Equal(c, uint32(success), successfulResponses, "expected %d successful responses but got %d", success, successfulResponses) + require.Equal(c, uint32(failure), failedResponses) + require.Equal(c, uint32(timeout), timeouts, "expected %d timeouts but got %d", timeout, timeouts) }, 10*time.Second, 100*time.Millisecond, "Failed to get dns response or unexpected response") } @@ -1251,9 +1231,7 @@ func (s *TracerSuite) TestUnconnectedUDPSendIPv4() { return cs.DPort == uint16(remotePort) }) - if !assert.Len(ct, outgoing, 1) { - return - } + require.Len(ct, outgoing, 1) assert.Equal(ct, bytesSent, int(outgoing[0].Monotonic.SentBytes)) }, 3*time.Second, 100*time.Millisecond) } @@ -1282,9 +1260,7 @@ func (s *TracerSuite) TestConnectedUDPSendIPv6() { outgoing = network.FilterConnections(connections, func(cs network.ConnectionStats) bool { return cs.DPort == uint16(remotePort) }) - if !assert.Len(ct, outgoing, 1) { - return - } + require.Len(ct, outgoing, 1) assert.Equal(ct, remoteAddr.IP.String(), outgoing[0].Dest.String()) assert.Equal(ct, bytesSent, int(outgoing[0].Monotonic.SentBytes)) diff --git a/pkg/trace/api/info_test.go b/pkg/trace/api/info_test.go index daecb81e0ec8..0a3a05810675 100644 --- a/pkg/trace/api/info_test.go +++ b/pkg/trace/api/info_test.go @@ -18,6 +18,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/DataDog/datadog-agent/pkg/obfuscate" "github.com/DataDog/datadog-agent/pkg/trace/config" @@ -365,9 +366,7 @@ func TestInfoHandler(t *testing.T) { req.Header.Add("Datadog-Container-ID", "id1") h.ServeHTTP(rec, req) var m map[string]any - if !assert.NoError(t, json.NewDecoder(rec.Body).Decode(&m)) { - return - } + require.NoError(t, json.NewDecoder(rec.Body).Decode(&m)) assert.NoError(t, ensureKeys(expectedKeys, m, "")) expectedContainerHash := fmt.Sprintf("%x", sha256.Sum256([]byte(strings.Join([]string{"kube_cluster_name:clusterA", "kube_namespace:namespace1"}, ",")))) assert.Equal(t, expectedContainerHash, rec.Header().Get(containerTagsHashHeader)) diff --git a/pkg/util/executable/executable_test.go b/pkg/util/executable/executable_test.go index bfc6354c1550..312d40c2b48a 100644 --- a/pkg/util/executable/executable_test.go +++ b/pkg/util/executable/executable_test.go @@ -14,6 +14,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestResolvePath(t *testing.T) { @@ -23,13 +24,9 @@ func TestResolvePath(t *testing.T) { } actualPath, err := ResolvePath(testProgram) - if !assert.NoError(t, err) { - return - } + require.NoError(t, err) - if !assert.NotEmpty(t, actualPath) { - return - } + require.NotEmpty(t, actualPath) if _, err := os.Stat(actualPath); os.IsNotExist(err) { assert.FailNowf(t, "Resolved path '%s' does not exist!", actualPath) @@ -43,14 +40,10 @@ func TestResolvePathIsAbsolute(t *testing.T) { } actualPath, err := ResolvePath(testProgram) - if !assert.NoError(t, err) { - return - } + require.NoError(t, err) absPath, err := filepath.Abs(actualPath) - if !assert.NoError(t, err) { - return - } + require.NoError(t, err) assert.Equal(t, absPath, actualPath) } @@ -59,7 +52,5 @@ func TestResolvePathFailure(t *testing.T) { testProgram := "badprogramname" _, err := ResolvePath(testProgram) - if !assert.NotNil(t, err) { - return - } + require.NotNil(t, err) } diff --git a/pkg/util/winutil/eventlog/subscription/subscription_test.go b/pkg/util/winutil/eventlog/subscription/subscription_test.go index 01c651c43746..9035fcffb425 100644 --- a/pkg/util/winutil/eventlog/subscription/subscription_test.go +++ b/pkg/util/winutil/eventlog/subscription/subscription_test.go @@ -792,9 +792,7 @@ func (s *GetEventsTestSuite) TestReadWhenNoMoreEvents() { eventRecords, err := getEventHandles(s.T(), s.ti, sub, 2*s.numEvents) require.NoError(s.T(), err) count := uint(len(eventRecords)) - if !assert.Equal(s.T(), 2*s.numEvents, count, fmt.Sprintf("Missing events, collected %d/%d events", count, 2*s.numEvents)) { - return - } + require.Equal(s.T(), 2*s.numEvents, count, fmt.Sprintf("Missing events, collected %d/%d events", count, 2*s.numEvents)) err = assertNoMoreEvents(s.T(), sub) require.NoError(s.T(), err) diff --git a/test/new-e2e/tests/agent-health/docker_permission_test.go b/test/new-e2e/tests/agent-health/docker_permission_test.go index 9a6740ad479c..bfd7bbed24b3 100644 --- a/test/new-e2e/tests/agent-health/docker_permission_test.go +++ b/test/new-e2e/tests/agent-health/docker_permission_test.go @@ -136,9 +136,8 @@ func (suite *dockerPermissionSuite) TestDockerPermissionIssueLifecycle() { var postRestartIssue *healthplatform.Issue require.EventuallyWithT(t, func(ct *assert.CollectT) { payloads, err := fakeIntake.GetAgentHealth() - if !assert.NoError(ct, err) || !assert.NotEmpty(ct, payloads, "Should receive health report after restart") { - return - } + require.NoError(ct, err) + require.NotEmpty(ct, payloads, "Should receive health report after restart") latest := payloads[len(payloads)-1] postRestartIssue = findIssue(t, latest, expectedIssueID) assert.NotNil(ct, postRestartIssue, "Docker permission issue should still be present after restart") diff --git a/test/new-e2e/tests/agent-log-pipelines/linux-log/file-tailing/file_tailing_test.go b/test/new-e2e/tests/agent-log-pipelines/linux-log/file-tailing/file_tailing_test.go index fa5a89640bc3..d4a75ea55717 100644 --- a/test/new-e2e/tests/agent-log-pipelines/linux-log/file-tailing/file_tailing_test.go +++ b/test/new-e2e/tests/agent-log-pipelines/linux-log/file-tailing/file_tailing_test.go @@ -16,6 +16,7 @@ import ( "github.com/DataDog/datadog-agent/test/new-e2e/tests/agent-log-pipelines/utils" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/DataDog/datadog-agent/test/e2e-framework/components/datadog/agentparams" scenec2 "github.com/DataDog/datadog-agent/test/e2e-framework/scenarios/aws/ec2" @@ -61,9 +62,7 @@ func (s *LinuxFakeintakeSuite) BeforeTest(suiteName, testName string) { // Ensure no logs are present in fakeintake before testing starts s.EventuallyWithT(func(c *assert.CollectT) { logs, err := s.Env().FakeIntake.Client().FilterLogs("hello") - if !assert.NoError(c, err, "Unable to filter logs by the service 'hello'.") { - return - } + require.NoError(c, err, "Unable to filter logs by the service 'hello'.") // If logs are found, print their content for debugging if !assert.Empty(c, logs, "Logs were found when none were expected.") { cat, _ := s.Env().RemoteHost.Execute(fmt.Sprintf("cat %s && cat %s/hello-world-2.log", logFilePath, utils.LinuxLogsFolderPath)) diff --git a/test/new-e2e/tests/agent-log-pipelines/windows-log/file-tailing/file_tailing_test.go b/test/new-e2e/tests/agent-log-pipelines/windows-log/file-tailing/file_tailing_test.go index e966bc1e0827..2b6a9810ee48 100644 --- a/test/new-e2e/tests/agent-log-pipelines/windows-log/file-tailing/file_tailing_test.go +++ b/test/new-e2e/tests/agent-log-pipelines/windows-log/file-tailing/file_tailing_test.go @@ -61,9 +61,7 @@ func (s *WindowsFakeintakeSuite) BeforeTest(suiteName, testName string) { // Ensure no logs are present in fakeintake before testing starts s.EventuallyWithT(func(c *assert.CollectT) { logs, err := s.Env().FakeIntake.Client().FilterLogs("hello") - if !assert.NoError(c, err, "Unable to filter logs by the service 'hello'.") { - return - } + require.NoError(c, err, "Unable to filter logs by the service 'hello'.") // If logs are found, print their content for debugging if !assert.Empty(c, logs, "Logs were found when none were expected") { cat, _ := s.Env().RemoteHost.Execute("type " + logFilePath) diff --git a/test/new-e2e/tests/agent-runtimes/infra/utils_test.go b/test/new-e2e/tests/agent-runtimes/infra/utils_test.go index 64f2cfbb5ab4..e08f97ae253f 100644 --- a/test/new-e2e/tests/agent-runtimes/infra/utils_test.go +++ b/test/new-e2e/tests/agent-runtimes/infra/utils_test.go @@ -11,6 +11,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/DataDog/datadog-agent/test/e2e-framework/testing/environments" "github.com/DataDog/datadog-agent/test/e2e-framework/testing/testcommon/check" @@ -93,10 +94,7 @@ func verifyCheckRuns(t *testing.T, env *environments.Host, checkName string) boo // by querying the agent status API. This is a helper function meant to be called within EventuallyWithT. func verifyCheckSchedulingViaStatusAPI(t *testing.T, c *assert.CollectT, env *environments.Host, checks []string, shouldBeScheduled bool) { scheduledChecks, err := getScheduledChecks(env) - if !assert.NoError(c, err, "Failed to get scheduled checks") { - t.Logf("Failed to retrieve scheduled checks, will retry...") - return - } + require.NoError(c, err, "Failed to get scheduled checks") t.Logf("Found %d check types in agent status", len(scheduledChecks)) diff --git a/test/new-e2e/tests/containers/base_test.go b/test/new-e2e/tests/containers/base_test.go index 692f36111cbb..da39d8b28594 100644 --- a/test/new-e2e/tests/containers/base_test.go +++ b/test/new-e2e/tests/containers/base_test.go @@ -164,14 +164,8 @@ func (suite *baseSuite[Env]) testMetric(args *testMetricArgs) { args.Filter.Name, fakeintake.WithMatchingTags[*aggregator.MetricSeries](regexTags), ) - // Can be replaced by require.NoErrorf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NoErrorf(c, err, "Failed to query fake intake") { - return - } - // Can be replaced by require.NoEmptyf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NotEmptyf(c, metrics, "No `%s` metrics yet", prettyMetricQuery) { - return - } + require.NoErrorf(c, err, "Failed to query fake intake") + require.NotEmptyf(c, metrics, "No `%s` metrics yet", prettyMetricQuery) // Check tags if expectedTags != nil { @@ -293,14 +287,8 @@ func (suite *baseSuite[Env]) testLog(args *testLogArgs) { args.Filter.Service, fakeintake.WithMatchingTags[*aggregator.Log](regexTags), ) - // Can be replaced by require.NoErrorf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NoErrorf(c, err, "Failed to query fake intake") { - return - } - // Can be replaced by require.NoEmptyf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NotEmptyf(c, logs, "No `%s` logs yet", prettyLogQuery) { - return - } + require.NoErrorf(c, err, "Failed to query fake intake") + require.NotEmptyf(c, logs, "No `%s` logs yet", prettyLogQuery) // Check tags if expectedTags != nil { @@ -426,14 +414,8 @@ func (suite *baseSuite[Env]) testCheckRun(args *testCheckRunArgs) { args.Filter.Name, fakeintake.WithMatchingTags[*aggregator.CheckRun](regexTags), ) - // Can be replaced by require.NoErrorf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NoErrorf(c, err, "Failed to query fake intake") { - return - } - // Can be replaced by require.NoEmptyf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NotEmptyf(c, checkRuns, "No `%s` checkRun yet", prettyCheckRunQuery) { - return - } + require.NoErrorf(c, err, "Failed to query fake intake") + require.NotEmptyf(c, checkRuns, "No `%s` checkRun yet", prettyCheckRunQuery) // Check tags if expectedTags != nil { @@ -539,14 +521,8 @@ func (suite *baseSuite[Env]) testEvent(args *testEventArgs) { args.Filter.Source, fakeintake.WithMatchingTags[*aggregator.Event](regexTags), ) - // Can be replaced by require.NoErrorf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NoErrorf(c, err, "Failed to query fake intake") { - return - } - // Can be replaced by require.NoEmptyf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NotEmptyf(c, events, "No `%s` events yet", prettyEventQuery) { - return - } + require.NoErrorf(c, err, "Failed to query fake intake") + require.NotEmptyf(c, events, "No `%s` events yet", prettyEventQuery) // Check tags if expectedTags != nil { diff --git a/test/new-e2e/tests/containers/ecs_test.go b/test/new-e2e/tests/containers/ecs_test.go index e0f0bcacc10f..00a2ac6508a1 100644 --- a/test/new-e2e/tests/containers/ecs_test.go +++ b/test/new-e2e/tests/containers/ecs_test.go @@ -118,10 +118,7 @@ func (suite *ecsSuite) Test00UpAndRunning() { MaxResults: pointer.Ptr(int32(10)), // Because `DescribeServices` takes at most 10 services in input NextToken: nextToken, }) - // Can be replaced by require.NoErrorf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NoErrorf(c, err, "Failed to list ECS services") { - return - } + require.NoErrorf(c, err, "Failed to list ECS services") nextToken = servicesList.NextToken @@ -148,9 +145,7 @@ func (suite *ecsSuite) Test00UpAndRunning() { MaxResults: pointer.Ptr(int32(100)), // Because `DescribeTasks` takes at most 100 tasks in input NextToken: nextToken, }) - if !assert.NoErrorf(c, err, "Failed to list ECS tasks for service %s", *serviceDescription.ServiceName) { - break - } + require.NoErrorf(c, err, "Failed to list ECS tasks for service %s", *serviceDescription.ServiceName) nextToken = tasksList.NextToken @@ -614,10 +609,7 @@ func (suite *ecsSuite) TestTraceTCP() { func (suite *ecsSuite) testTrace(taskName string) { suite.EventuallyWithTf(func(c *assert.CollectT) { traces, cerr := suite.Fakeintake.GetTraces() - // Can be replaced by require.NoErrorf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NoErrorf(c, cerr, "Failed to query fake intake") { - return - } + require.NoErrorf(c, cerr, "Failed to query fake intake") var err error // Iterate starting from the most recent traces diff --git a/test/new-e2e/tests/containers/k8s_test.go b/test/new-e2e/tests/containers/k8s_test.go index 4dd264f12c9b..be69ddc58c21 100644 --- a/test/new-e2e/tests/containers/k8s_test.go +++ b/test/new-e2e/tests/containers/k8s_test.go @@ -128,58 +128,37 @@ func (suite *k8sSuite) testUpAndRunning(waitFor time.Duration) { fields.OneTermNotEqualSelector("eks.amazonaws.com/compute-type", "fargate"), ).String(), }) - // Can be replaced by require.NoErrorf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NoErrorf(c, err, "Failed to list Linux nodes") { - return - } + require.NoErrorf(c, err, "Failed to list Linux nodes") windowsNodes, err := suite.Env().KubernetesCluster.Client().CoreV1().Nodes().List(ctx, metav1.ListOptions{ LabelSelector: fields.OneTermEqualSelector("kubernetes.io/os", "windows").String(), }) - // Can be replaced by require.NoErrorf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NoErrorf(c, err, "Failed to list Windows nodes") { - return - } + require.NoErrorf(c, err, "Failed to list Windows nodes") linuxPods, err := suite.Env().KubernetesCluster.Client().CoreV1().Pods("datadog").List(ctx, metav1.ListOptions{ LabelSelector: fields.OneTermEqualSelector("app", suite.Env().Agent.LinuxNodeAgent.LabelSelectors["app"]).String(), }) - // Can be replaced by require.NoErrorf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NoErrorf(c, err, "Failed to list Linux datadog agent pods") { - return - } + require.NoErrorf(c, err, "Failed to list Linux datadog agent pods") windowsPods, err := suite.Env().KubernetesCluster.Client().CoreV1().Pods("datadog").List(ctx, metav1.ListOptions{ LabelSelector: fields.OneTermEqualSelector("app", suite.Env().Agent.WindowsNodeAgent.LabelSelectors["app"]).String(), }) - // Can be replaced by require.NoErrorf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NoErrorf(c, err, "Failed to list Windows datadog agent pods") { - return - } + require.NoErrorf(c, err, "Failed to list Windows datadog agent pods") clusterAgentPods, err := suite.Env().KubernetesCluster.Client().CoreV1().Pods("datadog").List(ctx, metav1.ListOptions{ LabelSelector: fields.OneTermEqualSelector("app", suite.Env().Agent.LinuxClusterAgent.LabelSelectors["app"]).String(), }) - // Can be replaced by require.NoErrorf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NoErrorf(c, err, "Failed to list datadog cluster agent pods") { - return - } + require.NoErrorf(c, err, "Failed to list datadog cluster agent pods") clusterChecksPods, err := suite.Env().KubernetesCluster.Client().CoreV1().Pods("datadog").List(ctx, metav1.ListOptions{ LabelSelector: fields.OneTermEqualSelector("app", suite.Env().Agent.LinuxClusterChecks.LabelSelectors["app"]).String(), }) - // Can be replaced by require.NoErrorf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NoErrorf(c, err, "Failed to list datadog cluster checks runner pods") { - return - } + require.NoErrorf(c, err, "Failed to list datadog cluster checks runner pods") dogstatsdPods, err := suite.Env().KubernetesCluster.Client().CoreV1().Pods("dogstatsd-standalone").List(ctx, metav1.ListOptions{ LabelSelector: fields.OneTermEqualSelector("app", "dogstatsd-standalone").String(), }) - // Can be replaced by require.NoErrorf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NoErrorf(c, err, "Failed to list dogstatsd standalone pods") { - return - } + require.NoErrorf(c, err, "Failed to list dogstatsd standalone pods") assert.Len(c, linuxPods.Items, len(linuxNodes.Items)) assert.Len(c, windowsPods.Items, len(windowsNodes.Items)) @@ -348,10 +327,7 @@ func (suite *k8sSuite) testAgentCLI() { var stdout string suite.EventuallyWithT(func(c *assert.CollectT) { stdout, _, err = suite.Env().KubernetesCluster.KubernetesClient.PodExec("datadog", pod.Items[0].Name, "agent", []string{"agent", "check", "-t", "3", "container", "--table", "--delay", "1000", "--pause", "5000"}) - // Can be replaced by require.NoError(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NoError(c, err) { - return - } + require.NoError(c, err) matched, err := regexp.MatchString(`container\.memory\.usage\s+gauge\s+\d+\s+\d+`, stdout) if assert.NoError(c, err) { assert.Truef(c, matched, "Output of `agent check -r container` doesn’t contain the expected metric") @@ -366,10 +342,7 @@ func (suite *k8sSuite) testAgentCLI() { var stdout string suite.EventuallyWithT(func(c *assert.CollectT) { stdout, _, err = suite.Env().KubernetesCluster.KubernetesClient.PodExec("datadog", pod.Items[0].Name, "agent", []string{"env", "DD_LOG_LEVEL=off", "agent", "check", "-r", "container", "--table", "--delay", "1000", "--json"}) - // Can be replaced by require.NoError(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NoError(c, err) { - return - } + require.NoError(c, err) if !assert.Truef(c, json.Valid([]byte(stdout)), "Output of `agent check -r container --json` isn’t valid JSON") { var blob interface{} err := json.Unmarshal([]byte(stdout), &blob) @@ -1644,14 +1617,8 @@ func (suite *k8sSuite) TestContainerImage() { }() images, err := suite.Fakeintake.FilterContainerImages("ghcr.io/datadog/apps-nginx-server") - // Can be replaced by require.NoErrorf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NoErrorf(c, err, "Failed to query fake intake") { - return - } - // Can be replaced by require.NoEmptyf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NotEmptyf(c, images, "No container_image yet") { - return - } + require.NoErrorf(c, err, "Failed to query fake intake") + require.NotEmptyf(c, images, "No container_image yet") expectedTags := []*regexp.Regexp{ regexp.MustCompile(`^architecture:(amd|arm)64$`), @@ -1714,19 +1681,13 @@ func (suite *k8sSuite) TestSBOM() { }() sbomIDs, err := suite.Fakeintake.GetSBOMIDs() - // Can be replaced by require.NoErrorf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NoErrorf(c, err, "Failed to query fake intake") { - return - } + require.NoErrorf(c, err, "Failed to query fake intake") sbomIDs = lo.Filter(sbomIDs, func(id string, _ int) bool { return strings.HasPrefix(id, "ghcr.io/datadog/apps-nginx-server") }) - // Can be replaced by require.NoEmptyf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NotEmptyf(c, sbomIDs, "No SBOM for ghcr.io/datadog/apps-nginx-server yet") { - return - } + require.NotEmptyf(c, sbomIDs, "No SBOM for ghcr.io/datadog/apps-nginx-server yet") images := lo.FlatMap(sbomIDs, func(id string, _ int) []*aggregator.SBOMPayload { images, err := suite.Fakeintake.FilterSBOMs(id) @@ -1734,19 +1695,13 @@ func (suite *k8sSuite) TestSBOM() { return images }) - // Can be replaced by require.NoEmptyf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NotEmptyf(c, images, "No SBOM payload yet") { - return - } + require.NotEmptyf(c, images, "No SBOM payload yet") images = lo.Filter(images, func(image *aggregator.SBOMPayload, _ int) bool { return image.Status == sbom.SBOMStatus_SUCCESS }) - // Can be replaced by require.NoEmptyf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NotEmptyf(c, images, "No successful SBOM yet") { - return - } + require.NotEmptyf(c, images, "No successful SBOM yet") images = lo.Filter(images, func(image *aggregator.SBOMPayload, _ int) bool { cyclonedx := image.GetCyclonedx() @@ -1755,10 +1710,7 @@ func (suite *k8sSuite) TestSBOM() { cyclonedx.Metadata.Component != nil }) - // Can be replaced by require.NoEmptyf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NotEmptyf(c, images, "No SBOM with complete CycloneDX") { - return - } + require.NotEmptyf(c, images, "No SBOM with complete CycloneDX") for _, image := range images { if !assert.NotNil(c, image.GetCyclonedx().Metadata.Component.Properties) { @@ -1830,13 +1782,8 @@ func (suite *k8sSuite) TestContainerLifecycleEvents() { LabelSelector: fields.OneTermEqualSelector("app", "nginx").String(), FieldSelector: fields.OneTermEqualSelector("status.phase", "Running").String(), }) - // Can be replaced by require.NoErrorf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NoErrorf(c, err, "Failed to list nginx pods") { - return - } - if !assert.NotEmptyf(c, pods.Items, "Failed to find an nginx pod") { - return - } + require.NoErrorf(c, err, "Failed to list nginx pods") + require.NotEmptyf(c, pods.Items, "Failed to find an nginx pod") // Choose the oldest pod. // If we choose a pod that is too recent, there is a risk that we delete a pod that hasn’t been seen by the agent yet. @@ -1866,10 +1813,7 @@ func (suite *k8sSuite) TestContainerLifecycleEvents() { }() events, err := suite.Fakeintake.GetContainerLifecycleEvents() - // Can be replaced by require.NoErrorf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NoErrorf(c, err, "Failed to query fake intake") { - return - } + require.NoErrorf(c, err, "Failed to query fake intake") foundPodEvent := false @@ -1925,10 +1869,7 @@ func (suite *k8sSuite) testHPA(namespace, deployment string) { "kube_deployment:" + deployment, }), ) - // Can be replaced by require.NoErrorf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NoErrorf(c, err, "Failed to query fake intake") { - return - } + require.NoErrorf(c, err, "Failed to query fake intake") if !assert.NotEmptyf(c, metrics, "No `kubernetes_state.deployment.replicas_available{kube_namespace:%s,kube_deployment:%s}` metrics yet", namespace, deployment) { sendEvent("warning", fmt.Sprintf("No `kubernetes_state.deployment.replicas_available{kube_namespace:%s,kube_deployment:%s}` metrics yet", namespace, deployment), nil) return @@ -1975,10 +1916,7 @@ func (suite *k8sSuite) TestTraceTCP() { func (suite *k8sSuite) testTrace(kubeDeployment string) { suite.EventuallyWithTf(func(c *assert.CollectT) { traces, cerr := suite.Fakeintake.GetTraces() - // Can be replaced by require.NoErrorf(…) once https://github.com/stretchr/testify/pull/1481 is merged - if !assert.NoErrorf(c, cerr, "Failed to query fake intake") { - return - } + require.NoErrorf(c, cerr, "Failed to query fake intake") var err error // Iterate starting from the most recent traces diff --git a/test/new-e2e/tests/cspm/cspm_test.go b/test/new-e2e/tests/cspm/cspm_test.go index 91b2f7aa5a60..b49de90762b0 100644 --- a/test/new-e2e/tests/cspm/cspm_test.go +++ b/test/new-e2e/tests/cspm/cspm_test.go @@ -204,9 +204,7 @@ func (s *cspmTestSuite) TestMetrics() { assert.EventuallyWithT(s.T(), func(c *assert.CollectT) { metrics, err := s.Env().FakeIntake.Client().FilterMetrics("datadog.security_agent.compliance.running") - if !assert.NoError(c, err) { - return - } + require.NoError(c, err) if assert.NotEmpty(c, metrics) { s.T().Log("Metrics found: datadog.security_agent.compliance.running") } @@ -215,9 +213,7 @@ func (s *cspmTestSuite) TestMetrics() { s.T().Log("Waiting for datadog.security_agent.compliance.containers_running metrics") assert.EventuallyWithT(s.T(), func(c *assert.CollectT) { metrics, err := s.Env().FakeIntake.Client().FilterMetrics("datadog.security_agent.compliance.containers_running") - if !assert.NoError(c, err) { - return - } + require.NoError(c, err) if assert.NotEmpty(c, metrics) { s.T().Log("Metrics found: datadog.security_agent.compliance.containers_running") } diff --git a/test/new-e2e/tests/cws/windows_test.go b/test/new-e2e/tests/cws/windows_test.go index 22f400c5c8c1..9c1a5cd4de1b 100644 --- a/test/new-e2e/tests/cws/windows_test.go +++ b/test/new-e2e/tests/cws/windows_test.go @@ -202,24 +202,14 @@ func (a *agentSuiteWindows) Test03CreateFileSignal() { // Check app signal assert.EventuallyWithT(a.T(), func(c *assert.CollectT) { signal, err := a.apiClient.GetSignal(fmt.Sprintf("host:%s @workflow.rule.id:%s", a.Env().Agent.Client.Hostname(), signalRuleID)) - if !assert.NoError(c, err) { - return - } - if !assert.NotNil(c, signal) { - return - } + require.NoError(c, err) + require.NotNil(c, signal) assert.Contains(c, signal.Tags, "rule_id:"+strings.ToLower(agentRuleName), "unable to find rule_id tag") - if !assert.Contains(c, signal.AdditionalProperties, "attributes", "unable to find 'attributes' field in signal") { - return - } + require.Contains(c, signal.AdditionalProperties, "attributes", "unable to find 'attributes' field in signal") attributes := signal.AdditionalProperties["attributes"].(map[string]interface{}) - if !assert.Contains(c, attributes, "agent", "unable to find 'agent' field in signal's attributes") { - return - } + require.Contains(c, attributes, "agent", "unable to find 'agent' field in signal's attributes") agentContext := attributes["agent"].(map[string]interface{}) - if !assert.Contains(c, agentContext, "rule_id", "unable to find 'rule_id' in signal's agent context") { - return - } + require.Contains(c, agentContext, "rule_id", "unable to find 'rule_id' in signal's agent context") assert.Contains(c, agentContext["rule_id"], agentRuleName, "signal doesn't contain agent rule id") }, 4*time.Minute, 10*time.Second) } diff --git a/test/new-e2e/tests/netpath/network-path-integration/fake_traceroute_test.go b/test/new-e2e/tests/netpath/network-path-integration/fake_traceroute_test.go index 7a787bc54dd9..283cd58c844f 100644 --- a/test/new-e2e/tests/netpath/network-path-integration/fake_traceroute_test.go +++ b/test/new-e2e/tests/netpath/network-path-integration/fake_traceroute_test.go @@ -116,9 +116,7 @@ func (s *fakeTracerouteTestSuite) TestFakeTraceroute() { assert.EventuallyWithT(t, func(c *assert.CollectT) { nps, err := s.Env().FakeIntake.Client().GetLatestNetpathEvents() assert.NoError(c, err, "GetLatestNetpathEvents() errors") - if !assert.NotNil(c, nps, "GetLatestNetpathEvents() returned nil netpaths") { - return - } + require.NotNil(c, nps, "GetLatestNetpathEvents() returned nil netpaths") udpPath := s.expectNetpath(c, func(np *aggregator.Netpath) bool { return np.Destination.Hostname == targetIP.String() && np.Protocol == "UDP" diff --git a/test/new-e2e/tests/npm/agentenv_npm_test.go b/test/new-e2e/tests/npm/agentenv_npm_test.go index 2c3b4ff2e960..5849903783d9 100644 --- a/test/new-e2e/tests/npm/agentenv_npm_test.go +++ b/test/new-e2e/tests/npm/agentenv_npm_test.go @@ -17,6 +17,7 @@ import ( scenec2 "github.com/DataDog/datadog-agent/test/e2e-framework/scenarios/aws/ec2" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) type vmSuiteEx6 struct { @@ -41,9 +42,7 @@ func (v *vmSuiteEx6) Test1_FakeIntakeNPM() { v.Env().RemoteHost.MustExecute("curl http://www.datadoghq.com") hostnameNetID, err := v.Env().FakeIntake.Client().GetConnectionsNames() - if !assert.NoError(c, err, "fakeintake GetConnectionsNames() error") { - return - } + require.NoError(c, err, "fakeintake GetConnectionsNames() error") if assert.NotZero(c, len(hostnameNetID), "no connections yet") { t.Logf("hostname+networkID %v seen connections", hostnameNetID) diff --git a/test/new-e2e/tests/npm/cilium_lb_conntracker_test.go b/test/new-e2e/tests/npm/cilium_lb_conntracker_test.go index 321dd4ac1a70..c08d55095982 100644 --- a/test/new-e2e/tests/npm/cilium_lb_conntracker_test.go +++ b/test/new-e2e/tests/npm/cilium_lb_conntracker_test.go @@ -137,9 +137,7 @@ func (suite *ciliumLBConntrackerTestSuite) TestCiliumConntracker() { return } - if !assert.NotNil(collect, c.IpTranslation, "ip translation is nil for service connection") { - return - } + require.NotNil(collect, c.IpTranslation, "ip translation is nil for service connection") svcConns = append(svcConns, c) } diff --git a/test/new-e2e/tests/remote-config/utils_test.go b/test/new-e2e/tests/remote-config/utils_test.go index 47b4d2bc226a..19f0a199f4ff 100644 --- a/test/new-e2e/tests/remote-config/utils_test.go +++ b/test/new-e2e/tests/remote-config/utils_test.go @@ -13,6 +13,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/DataDog/datadog-agent/test/e2e-framework/testing/components" ) @@ -32,9 +33,7 @@ func assertAgentLogsEventually(t *testing.T, rh *components.RemoteHost, agentNam assert.EventuallyWithTf(t, func(c *assert.CollectT) { // read agent logs agentLogs, err := rh.ReadFilePrivileged(remoteLogsPath) - if !assert.NoError(c, err) { - return - } + require.NoError(c, err) logs := string(agentLogs) for _, log := range missingLogs { if strings.Contains(logs, log) { diff --git a/test/new-e2e/tests/windows/install-test/install_test.go b/test/new-e2e/tests/windows/install-test/install_test.go index f41b2332da49..b3b61a07ca33 100644 --- a/test/new-e2e/tests/windows/install-test/install_test.go +++ b/test/new-e2e/tests/windows/install-test/install_test.go @@ -22,6 +22,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" ) @@ -423,16 +424,10 @@ func (s *testInstallOptsSuite) TestInstallOpts() { var boundPort boundport.BoundPort s.Require().EventuallyWithTf(func(c *assert.CollectT) { pid, err := windowsCommon.GetServicePID(vm, "DatadogAgent") - if !assert.NoError(c, err) { - return - } + require.NoError(c, err) boundPort, err = common.GetBoundPort(vm, "tcp", cmdPort) - if !assert.NoError(c, err) { - return - } - if !assert.NotNil(c, boundPort, "port tcp/%d should be bound", cmdPort) { - return - } + require.NoError(c, err) + require.NotNil(c, boundPort, "port tcp/%d should be bound", cmdPort) assert.Equalf(c, pid, boundPort.PID(), "port tcp/%d should be bound by the agent", cmdPort) }, 1*time.Minute, 500*time.Millisecond, "port tcp/%d should be bound by the agent", cmdPort) s.Require().EqualValues("127.0.0.1", boundPort.LocalAddress(), "agent should only be listening locally") diff --git a/test/new-e2e/tests/windows/install-test/upgrade_test.go b/test/new-e2e/tests/windows/install-test/upgrade_test.go index 3d056f1ee9f3..ab4748478c0a 100644 --- a/test/new-e2e/tests/windows/install-test/upgrade_test.go +++ b/test/new-e2e/tests/windows/install-test/upgrade_test.go @@ -403,9 +403,7 @@ func (s *testUpgradeFromV5Suite) installAgent5() { s.Assert().EventuallyWithT(func(t *assert.CollectT) { cmd := fmt.Sprintf(`& "%s\embedded\python.exe" "%s\agent\agent.py" info`, installPath, installPath) out, err := host.Execute(cmd) - if !assert.NoError(t, err, "should get agent info") { - return - } + require.NoError(t, err, "should get agent info") s.T().Logf("Agent 5 info:\n%s", out) assert.Contains(t, out, agentPackage.AgentVersion(), "info should have agent 5 version") }, 5*time.Minute, 5*time.Second, "should get agent 5 info")