Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore]: enable go-require rule from testifylint #11174

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ linters-settings:
# TODO: enable all rules
disable:
- float-compare
- go-require
- require-error
enable-all: true

Expand Down
2 changes: 1 addition & 1 deletion Makefile.Common
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ SEMCONVGEN := $(TOOLS_BIN_DIR)/semconvgen
SEMCONVKIT := $(TOOLS_BIN_DIR)/semconvkit
TESTIFYLINT := $(TOOLS_BIN_DIR)/testifylint

TESTIFYLINT_OPT?= --enable-all --disable=float-compare,go-require,require-error
TESTIFYLINT_OPT?= --enable-all --disable=float-compare,require-error

.PHONY: install-tools
install-tools: $(TOOLS_BIN_NAMES)
Expand Down
8 changes: 4 additions & 4 deletions config/confighttp/compression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestHTTPClientCompression(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, err := io.ReadAll(r.Body)
require.NoError(t, err, "failed to read request body: %v", err)
assert.NoError(t, err, "failed to read request body: %v", err)
assert.EqualValues(t, tt.reqBody, body)
w.WriteHeader(http.StatusOK)
}))
Expand Down Expand Up @@ -125,7 +125,7 @@ func TestHTTPCustomDecompression(t *testing.T) {
return
}

require.NoError(t, err, "failed to read request body: %v", err)
assert.NoError(t, err, "failed to read request body: %v", err)
assert.EqualValues(t, "decompressed body", string(body))
w.WriteHeader(http.StatusOK)
})
Expand Down Expand Up @@ -250,7 +250,7 @@ func TestHTTPContentDecompressionHandler(t *testing.T) {
return
}

require.NoError(t, err, "failed to read request body: %v", err)
assert.NoError(t, err, "failed to read request body: %v", err)
assert.EqualValues(t, testBody, string(body))
w.WriteHeader(http.StatusOK)
}), defaultMaxRequestBodySize, defaultErrorHandler, defaultCompressionAlgorithms, noDecoders))
Expand Down Expand Up @@ -279,7 +279,7 @@ func TestHTTPContentCompressionRequestWithNilBody(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
body, err := io.ReadAll(r.Body)
require.NoError(t, err, "failed to read request body: %v", err)
assert.NoError(t, err, "failed to read request body: %v", err)
assert.EqualValues(t, compressedGzipBody.Bytes(), body)
}))
defer server.Close()
Expand Down
2 changes: 1 addition & 1 deletion config/confighttp/confighttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,7 @@ func BenchmarkHttpRequest(b *testing.B) {
componenttest.NewNopTelemetrySettings(),
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, errWrite := fmt.Fprint(w, "test")
require.NoError(b, errWrite)
assert.NoError(b, errWrite)
}))
require.NoError(b, err)
ln, err := hss.ToListener(context.Background())
Expand Down
18 changes: 9 additions & 9 deletions exporter/exporterhelper/batch_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,8 @@ func TestBatchSender_ShutdownDeadlock(t *testing.T) {
sink := newFakeRequestSink()

// Send 2 concurrent requests
go func() { require.NoError(t, be.send(context.Background(), &fakeRequest{items: 4, sink: sink})) }()
go func() { require.NoError(t, be.send(context.Background(), &fakeRequest{items: 4, sink: sink})) }()
go func() { assert.NoError(t, be.send(context.Background(), &fakeRequest{items: 4, sink: sink})) }()
go func() { assert.NoError(t, be.send(context.Background(), &fakeRequest{items: 4, sink: sink})) }()

// Wait for the requests to enter the merge function
<-waitMerge
Expand All @@ -561,7 +561,7 @@ func TestBatchSender_ShutdownDeadlock(t *testing.T) {
doneShutdown := make(chan struct{})
go func() {
close(startShutdown)
require.NoError(t, be.Shutdown(context.Background()))
assert.NoError(t, be.Shutdown(context.Background()))
close(doneShutdown)
}()
<-startShutdown
Expand Down Expand Up @@ -590,7 +590,7 @@ func TestBatchSenderWithTimeout(t *testing.T) {
for i := 0; i < 3; i++ {
wg.Add(1)
go func() {
require.NoError(t, be.send(context.Background(), &fakeRequest{items: 4, sink: sink}))
assert.NoError(t, be.send(context.Background(), &fakeRequest{items: 4, sink: sink}))
wg.Done()
}()
}
Expand Down Expand Up @@ -644,11 +644,11 @@ func TestBatchSenderTimerResetNoConflict(t *testing.T) {

// Send 2 concurrent requests that should be merged in one batch in the same interval as the flush timer
go func() {
require.NoError(t, be.send(context.Background(), &fakeRequest{items: 4, sink: sink}))
assert.NoError(t, be.send(context.Background(), &fakeRequest{items: 4, sink: sink}))
}()
time.Sleep(30 * time.Millisecond)
go func() {
require.NoError(t, be.send(context.Background(), &fakeRequest{items: 4, sink: sink}))
assert.NoError(t, be.send(context.Background(), &fakeRequest{items: 4, sink: sink}))
}()

// The batch should be sent either with the flush interval or by reaching the minimum items size with no conflict
Expand Down Expand Up @@ -676,10 +676,10 @@ func TestBatchSenderTimerFlush(t *testing.T) {

// Send 2 concurrent requests that should be merged in one batch and sent immediately
go func() {
require.NoError(t, be.send(context.Background(), &fakeRequest{items: 4, sink: sink}))
assert.NoError(t, be.send(context.Background(), &fakeRequest{items: 4, sink: sink}))
}()
go func() {
require.NoError(t, be.send(context.Background(), &fakeRequest{items: 4, sink: sink}))
assert.NoError(t, be.send(context.Background(), &fakeRequest{items: 4, sink: sink}))
}()
assert.EventuallyWithT(t, func(c *assert.CollectT) {
assert.LessOrEqual(c, uint64(1), sink.requestsCount.Load())
Expand All @@ -688,7 +688,7 @@ func TestBatchSenderTimerFlush(t *testing.T) {

// Send another request that should be flushed after 100ms instead of 50ms since last flush
go func() {
require.NoError(t, be.send(context.Background(), &fakeRequest{items: 4, sink: sink}))
assert.NoError(t, be.send(context.Background(), &fakeRequest{items: 4, sink: sink}))
}()

// Confirm that it is not flushed in 50ms
Expand Down
2 changes: 1 addition & 1 deletion exporter/internal/queue/persistent_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ func TestPersistentQueueStartWithNonDispatchedConcurrent(t *testing.T) {
go func() {
defer conWg.Done()
for i := 0; i < 10; i++ {
require.True(t, pq.Consume(func(context.Context, tracesRequest) error { return nil }))
assert.True(t, pq.Consume(func(context.Context, tracesRequest) error { return nil }))
}
}()
}
Expand Down
16 changes: 8 additions & 8 deletions exporter/otlphttpexporter/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ func TestErrorResponses(t *testing.T) {
writer.WriteHeader(test.responseStatus)
if test.responseBody != nil {
msg, err := proto.Marshal(test.responseBody.Proto())
require.NoError(t, err)
assert.NoError(t, err)
_, err = writer.Write(msg)
require.NoError(t, err)
assert.NoError(t, err)
}
})
defer srv.Close()
Expand Down Expand Up @@ -461,10 +461,10 @@ func TestPartialSuccess_logs(t *testing.T) {
partial.SetErrorMessage("hello")
partial.SetRejectedLogRecords(1)
b, err := response.MarshalProto()
require.NoError(t, err)
assert.NoError(t, err)
writer.Header().Set("Content-Type", "application/x-protobuf")
_, err = writer.Write(b)
require.NoError(t, err)
assert.NoError(t, err)
})
defer srv.Close()

Expand Down Expand Up @@ -801,10 +801,10 @@ func TestPartialSuccess_traces(t *testing.T) {
partial.SetErrorMessage("hello")
partial.SetRejectedSpans(1)
bytes, err := response.MarshalProto()
require.NoError(t, err)
assert.NoError(t, err)
writer.Header().Set("Content-Type", "application/x-protobuf")
_, err = writer.Write(bytes)
require.NoError(t, err)
assert.NoError(t, err)
})
defer srv.Close()

Expand Down Expand Up @@ -841,10 +841,10 @@ func TestPartialSuccess_metrics(t *testing.T) {
partial.SetErrorMessage("hello")
partial.SetRejectedDataPoints(1)
bytes, err := response.MarshalProto()
require.NoError(t, err)
assert.NoError(t, err)
writer.Header().Set("Content-Type", "application/x-protobuf")
_, err = writer.Write(bytes)
require.NoError(t, err)
assert.NoError(t, err)
})
defer srv.Close()

Expand Down
10 changes: 5 additions & 5 deletions internal/e2e/otlphttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,18 @@ func TestIssue_4221(t *testing.T) {
svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
defer func() { assert.NoError(t, r.Body.Close()) }()
compressedData, err := io.ReadAll(r.Body)
require.NoError(t, err)
assert.NoError(t, err)
gzipReader, err := gzip.NewReader(bytes.NewReader(compressedData))
require.NoError(t, err)
assert.NoError(t, err)
data, err := io.ReadAll(gzipReader)
require.NoError(t, err)
assert.NoError(t, err)
base64Data := base64.StdEncoding.EncodeToString(data)
// Verify same base64 encoded string is received.
assert.Equal(t, "CscBCkkKIAoMc2VydmljZS5uYW1lEhAKDnVvcC5zdGFnZS1ldS0xCiUKGW91dHN5c3RlbXMubW9kdWxlLnZlcnNpb24SCAoGOTAzMzg2EnoKEQoMdW9wX2NhbmFyaWVzEgExEmUKEEMDhT8Ib0+Mhs8Zi2VR34QSCOVRPDJ5XEG5IgA5QE41aASRrxZBQE41aASRrxZKEAoKc3Bhbl9pbmRleBICGANKHwoNY29kZS5mdW5jdGlvbhIOCgxteUZ1bmN0aW9uMzZ6AA==", base64Data)
unbase64Data, err := base64.StdEncoding.DecodeString(base64Data)
require.NoError(t, err)
assert.NoError(t, err)
tr := ptraceotlp.NewExportRequest()
require.NoError(t, tr.UnmarshalProto(unbase64Data))
assert.NoError(t, tr.UnmarshalProto(unbase64Data))
span := tr.Traces().ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0)
traceID := span.TraceID()
assert.Equal(t, "4303853f086f4f8c86cf198b6551df84", hex.EncodeToString(traceID[:]))
Expand Down
2 changes: 1 addition & 1 deletion otelcol/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ func startCollector(ctx context.Context, t *testing.T, col *Collector) *sync.Wai
wg.Add(1)
go func() {
defer wg.Done()
require.NoError(t, col.Run(ctx))
assert.NoError(t, col.Run(ctx))
}()
return wg
}
Expand Down
Loading