Skip to content

Commit

Permalink
testifylint: enable go-require
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
  • Loading branch information
mmorel-35 committed Sep 14, 2024
1 parent 7d6ebaa commit a866dd6
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 39 deletions.
13 changes: 1 addition & 12 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,18 +223,7 @@ linters-settings:
testifylint:
disable:
- float-compare
- go-require
enable:
- bool-compare
- compares
- empty
- error-is-as
- error-nil
- expected-actual
- len
- require-error
- suite-dont-use-pkg
- suite-extra-assert-call
enable-all: true

run:
go: "1.22"
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/app/configmanager/grpc/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func initializeGRPCTestServer(t *testing.T, beforeServe func(server *grpc.Server
beforeServe(server)
go func() {
err := server.Serve(lis)
require.NoError(t, err)
assert.NoError(t, err)
}()
return server, lis.Addr()
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/app/reporter/grpc/collector_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func initializeGRPCTestServer(t *testing.T, beforeServe func(server *grpc.Server
var wg sync.WaitGroup
wg.Add(1)
go func() {
require.NoError(t, server.Serve(lis))
assert.NoError(t, server.Serve(lis))
wg.Done()
}()
t.Cleanup(func() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/app/servers/thriftudp/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestTUDPServerTransportIsOpen(t *testing.T) {
go func() {
time.Sleep(2 * time.Millisecond)
err = trans.Close()
require.NoError(t, err)
assert.NoError(t, err)
wg.Done()
}()

Expand Down
3 changes: 2 additions & 1 deletion cmd/agent/app/testutils/mock_grpc_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"sync"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"

Expand All @@ -33,7 +34,7 @@ func StartGRPCCollector(t *testing.T) *GrpcCollector {
handler := &mockSpanHandler{t: t}
api_v2.RegisterCollectorServiceServer(server, handler)
go func() {
require.NoError(t, server.Serve(lis))
assert.NoError(t, server.Serve(lis))

Check warning on line 37 in cmd/agent/app/testutils/mock_grpc_collector.go

View check run for this annotation

Codecov / codecov/patch

cmd/agent/app/testutils/mock_grpc_collector.go#L37

Added line #L37 was not covered by tests
}()
return &GrpcCollector{
mockSpanHandler: handler,
Expand Down
2 changes: 1 addition & 1 deletion cmd/anonymizer/app/query/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func newTestServer(t *testing.T) *testServer {
var exited sync.WaitGroup
exited.Add(1)
go func() {
require.NoError(t, server.Serve(lis))
assert.NoError(t, server.Serve(lis))
exited.Done()
}()
t.Cleanup(func() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/collector/app/handler/grpc_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func initializeGRPCTestServer(t *testing.T, beforeServe func(s *grpc.Server)) (*
require.NoError(t, err)
go func() {
err := server.Serve(lis)
require.NoError(t, err)
assert.NoError(t, err)
}()
return server, lis.Addr()
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/query/app/apiv3/grpc_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func newGrpcServer(t *testing.T, handler *Handler) (*grpc.Server, net.Addr) {
require.NoError(t, err)
go func() {
err := server.Serve(lis)
require.NoError(t, err)
assert.NoError(t, err)
}()
t.Cleanup(func() { server.Stop() })
return server, lis.Addr()
Expand Down
2 changes: 1 addition & 1 deletion cmd/query/app/grpc_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func newGRPCServer(t *testing.T, q *querysvc.QueryService, mq querysvc.MetricsQu

go func() {
err := grpcServer.Serve(lis)
require.NoError(t, err)
assert.NoError(t, err)
}()

return grpcServer, lis.Addr()
Expand Down
3 changes: 2 additions & 1 deletion internal/grpctest/reflection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
Expand All @@ -24,7 +25,7 @@ func TestReflectionServiceValidator(t *testing.T) {

go func() {
err := server.Serve(listener)
require.NoError(t, err)
assert.NoError(t, err)
}()
defer server.Stop()

Expand Down
8 changes: 4 additions & 4 deletions pkg/es/client/index_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func TestClientCreateAliases(t *testing.T) {
assert.Equal(t, http.MethodPost, req.Method)
assert.Equal(t, "Basic foobar", req.Header.Get("Authorization"))
body, err := io.ReadAll(req.Body)
require.NoError(t, err)
assert.NoError(t, err)
assert.Equal(t, expectedRequestBody, string(body))
res.WriteHeader(test.responseCode)
res.Write([]byte(test.response))
Expand Down Expand Up @@ -445,7 +445,7 @@ func TestClientDeleteAliases(t *testing.T) {
assert.Equal(t, http.MethodPost, req.Method)
assert.Equal(t, "Basic foobar", req.Header.Get("Authorization"))
body, err := io.ReadAll(req.Body)
require.NoError(t, err)
assert.NoError(t, err)
assert.Equal(t, expectedRequestBody, string(body))
res.WriteHeader(test.responseCode)
res.Write([]byte(test.response))
Expand Down Expand Up @@ -508,7 +508,7 @@ func TestClientCreateTemplate(t *testing.T) {
assert.Equal(t, http.MethodPut, req.Method)
assert.Equal(t, "Basic foobar", req.Header.Get("Authorization"))
body, err := io.ReadAll(req.Body)
require.NoError(t, err)
assert.NoError(t, err)
assert.Equal(t, templateContent, string(body))

res.WriteHeader(test.responseCode)
Expand Down Expand Up @@ -562,7 +562,7 @@ func TestRollover(t *testing.T) {
assert.Equal(t, http.MethodPost, req.Method)
assert.Equal(t, "Basic foobar", req.Header.Get("Authorization"))
body, err := io.ReadAll(req.Body)
require.NoError(t, err)
assert.NoError(t, err)
assert.Equal(t, expectedRequestBody, string(body))

res.WriteHeader(test.responseCode)
Expand Down
9 changes: 5 additions & 4 deletions pkg/es/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

Expand Down Expand Up @@ -85,25 +86,25 @@ func TestNewClient(t *testing.T) {
defer certFilePath.Close()

testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
require.Equal(t, http.MethodGet, req.Method)
assert.Equal(t, http.MethodGet, req.Method)
res.WriteHeader(http.StatusOK)
res.Write(mockEsServerResponseWithVersion0)
}))
defer testServer.Close()
testServer1 := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
require.Equal(t, http.MethodGet, req.Method)
assert.Equal(t, http.MethodGet, req.Method)
res.WriteHeader(http.StatusOK)
res.Write(mockEsServerResponseWithVersion1)
}))
defer testServer1.Close()
testServer2 := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
require.Equal(t, http.MethodGet, req.Method)
assert.Equal(t, http.MethodGet, req.Method)
res.WriteHeader(http.StatusOK)
res.Write(mockEsServerResponseWithVersion2)
}))
defer testServer2.Close()
testServer8 := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
require.Equal(t, http.MethodGet, req.Method)
assert.Equal(t, http.MethodGet, req.Method)
res.WriteHeader(http.StatusOK)
res.Write(mockEsServerResponseWithVersion8)
}))
Expand Down
5 changes: 2 additions & 3 deletions pkg/hostname/hostname_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/jaegertracing/jaeger/pkg/testutils"
)
Expand All @@ -24,13 +23,13 @@ func TestAsIdentifier(t *testing.T) {
go func() {
var err error
hostname1, err = AsIdentifier()
require.NoError(t, err)
assert.NoError(t, err)
wg.Done()
}()
go func() {
var err error
hostname2, err = AsIdentifier()
require.NoError(t, err)
assert.NoError(t, err)
wg.Done()
}()
wg.Wait()
Expand Down
8 changes: 4 additions & 4 deletions plugin/metrics/prometheus/metricsstore/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func TestGetErrorRatesZero(t *testing.T) {
defer r.Body.Close()

u, err := url.Parse("http://" + r.Host + r.RequestURI + "?" + string(body))
require.NoError(t, err)
assert.NoError(t, err)

q := u.Query()
promQuery := q.Get("query")
Expand Down Expand Up @@ -564,7 +564,7 @@ func TestGetErrorRatesNull(t *testing.T) {
defer r.Body.Close()

u, err := url.Parse("http://" + r.Host + r.RequestURI + "?" + string(body))
require.NoError(t, err)
assert.NoError(t, err)

q := u.Query()
promQuery := q.Get("query")
Expand Down Expand Up @@ -635,7 +635,7 @@ func TestGetErrorRatesErrors(t *testing.T) {
defer r.Body.Close()

u, err := url.Parse("http://" + r.Host + r.RequestURI + "?" + string(body))
require.NoError(t, err)
assert.NoError(t, err)

q := u.Query()
promQuery := q.Get("query")
Expand Down Expand Up @@ -879,7 +879,7 @@ func startMockPrometheusServer(t *testing.T, wantPromQlQuery string, wantWarning
defer r.Body.Close()

u, err := url.Parse("http://" + r.Host + r.RequestURI + "?" + string(body))
require.NoError(t, err)
assert.NoError(t, err)

q := u.Query()
promQuery := q.Get("query")
Expand Down
6 changes: 3 additions & 3 deletions plugin/storage/es/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,10 @@ func testPasswordFromFile(t *testing.T, f *Factory, getClient func() es.Client,
t.Logf("request to fake ES server: %v", r)
// epecting header in the form Authorization:[Basic OmZpcnN0IHBhc3N3b3Jk]
h := strings.Split(r.Header.Get("Authorization"), " ")
require.Len(t, h, 2)
require.Equal(t, "Basic", h[0])
assert.Len(t, h, 2)
assert.Equal(t, "Basic", h[0])
authBytes, err := base64.StdEncoding.DecodeString(h[1])
require.NoError(t, err, "header: %s", h)
assert.NoError(t, err, "header: %s", h)
auth := string(authBytes)
authReceived.Store(auth, auth)
t.Logf("request to fake ES server contained auth=%s", auth)
Expand Down

0 comments on commit a866dd6

Please sign in to comment.