Skip to content

Commit

Permalink
[chore]: enable go-require rule from testifylint
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 committed Sep 14, 2024
1 parent 3b50b38 commit 61c2454
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 26 deletions.
13 changes: 11 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ run:
# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
formats: colored-line-number
formats:
- format: colored-line-number

# print lines of code with issue, default is true
print-issued-lines: true
Expand Down Expand Up @@ -126,7 +127,6 @@ linters-settings:
disable:
- float-compare
- formatter
- go-require
- require-error
enable-all: true

Expand Down Expand Up @@ -174,3 +174,12 @@ issues:
- EXC0009
- EXC0010
- EXC0011

# Maximum issues count per one linter.
# Set to 0 to disable.
# Default: 50
max-issues-per-linter: 0
# Maximum count of issues with the same text.
# Set to 0 to disable.
# Default: 3
max-same-issues: 0
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,formatter,go-require,require-error
TESTIFYLINT_OPT?= --enable-all --disable=float-compare,formatter,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

0 comments on commit 61c2454

Please sign in to comment.