Skip to content

Commit

Permalink
chore(lint): relinted
Browse files Browse the repository at this point in the history
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
  • Loading branch information
fredbi committed Mar 4, 2024
1 parent e6a1173 commit 35b5892
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 43 deletions.
12 changes: 8 additions & 4 deletions client/opentelemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func Test_OpenTelemetryRuntime_submit(t *testing.T) {
otel.SetTracerProvider(tp)

tracer := tp.Tracer("go-runtime")
ctx, _ := tracer.Start(context.Background(), "op")
ctx, span := tracer.Start(context.Background(), "op")
defer span.End()

assertOpenTelemetrySubmit(t, testOperation(ctx), exporter, 1)
}
Expand All @@ -48,7 +49,8 @@ func Test_OpenTelemetryRuntime_submit_nilAuthInfo(t *testing.T) {
otel.SetTracerProvider(tp)

tracer := tp.Tracer("go-runtime")
ctx, _ := tracer.Start(context.Background(), "op")
ctx, span := tracer.Start(context.Background(), "op")
defer span.End()

operation := testOperation(ctx)
operation.AuthInfo = nil
Expand All @@ -66,7 +68,8 @@ func Test_OpenTelemetryRuntime_submit_nilContext(t *testing.T) {
otel.SetTracerProvider(tp)

tracer := tp.Tracer("go-runtime")
ctx, _ := tracer.Start(context.Background(), "op")
ctx, span := tracer.Start(context.Background(), "op")
defer span.End()
operation := testOperation(ctx)
operation.Context = nil

Expand All @@ -86,7 +89,8 @@ func Test_injectOpenTelemetrySpanContext(t *testing.T) {
otel.SetTracerProvider(tp)

tracer := tp.Tracer("go-runtime")
ctx, _ := tracer.Start(context.Background(), "op")
ctx, span := tracer.Start(context.Background(), "op")
defer span.End()
operation := testOperation(ctx)

header := map[string][]string{}
Expand Down
2 changes: 1 addition & 1 deletion client/opentracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func testOperation(ctx context.Context) *runtime.ClientOperation {
Reader: runtime.ClientResponseReaderFunc(func(runtime.ClientResponse, runtime.Consumer) (interface{}, error) {
return nil, nil
}),
Params: runtime.ClientRequestWriterFunc(func(req runtime.ClientRequest, reg strfmt.Registry) error {
Params: runtime.ClientRequestWriterFunc(func(_ runtime.ClientRequest, _ strfmt.Registry) error {
return nil
}),
AuthInfo: PassThroughAuth,
Expand Down
4 changes: 2 additions & 2 deletions client/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ func TestBuildRequest_BuildHTTP_Files(t *testing.T) {
emptyFile, err := os.CreateTemp("", "empty")
require.NoError(t, err)

reqWrtr := runtime.ClientRequestWriterFunc(func(req runtime.ClientRequest, reg strfmt.Registry) error {
reqWrtr := runtime.ClientRequestWriterFunc(func(req runtime.ClientRequest, _ strfmt.Registry) error {
_ = req.SetFormParam("something", "some value")
_ = req.SetFileParam("file", mustGetFile("./runtime.go"))
_ = req.SetFileParam("otherfiles", mustGetFile("./runtime.go"), mustGetFile("./request.go"))
Expand Down Expand Up @@ -736,7 +736,7 @@ func TestGetBodyCallsBeforeRoundTrip(t *testing.T) {
bodyContent, e := io.ReadAll(io.Reader(body))
require.NoError(t, e)

require.EqualValues(t, req.ContentLength, len(bodyContent))
require.Len(t, bodyContent, int(req.ContentLength))
require.EqualValues(t, "\"test body\"\n", string(bodyContent))

// Read the body a second time before sending the request
Expand Down
3 changes: 2 additions & 1 deletion client/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"crypto/tls"
"crypto/x509"
"encoding/pem"
"errors"
"fmt"
"mime"
"net/http"
Expand Down Expand Up @@ -142,7 +143,7 @@ func TLSClientAuth(opts TLSClientOptions) (*tls.Config, error) {
return nil, fmt.Errorf("tls client priv key: %v", err)
}
default:
return nil, fmt.Errorf("tls client priv key: unsupported key type")
return nil, errors.New("tls client priv key: unsupported key type")
}

block = pem.Block{Type: "PRIVATE KEY", Bytes: keyBytes}
Expand Down
26 changes: 13 additions & 13 deletions client/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestRuntime_Concurrent(t *testing.T) {
}))
defer server.Close()

rwrtr := runtime.ClientRequestWriterFunc(func(req runtime.ClientRequest, _ strfmt.Registry) error {
rwrtr := runtime.ClientRequestWriterFunc(func(_ runtime.ClientRequest, _ strfmt.Registry) error {
return nil
})

Expand Down Expand Up @@ -149,7 +149,7 @@ func TestRuntime_Canary(t *testing.T) {
}))
defer server.Close()

rwrtr := runtime.ClientRequestWriterFunc(func(req runtime.ClientRequest, _ strfmt.Registry) error {
rwrtr := runtime.ClientRequestWriterFunc(func(_ runtime.ClientRequest, _ strfmt.Registry) error {
return nil
})

Expand Down Expand Up @@ -200,7 +200,7 @@ func TestRuntime_XMLCanary(t *testing.T) {
}))
defer server.Close()

rwrtr := runtime.ClientRequestWriterFunc(func(req runtime.ClientRequest, _ strfmt.Registry) error {
rwrtr := runtime.ClientRequestWriterFunc(func(_ runtime.ClientRequest, _ strfmt.Registry) error {
return nil
})

Expand Down Expand Up @@ -242,7 +242,7 @@ func TestRuntime_TextCanary(t *testing.T) {
}))
defer server.Close()

rwrtr := runtime.ClientRequestWriterFunc(func(req runtime.ClientRequest, _ strfmt.Registry) error {
rwrtr := runtime.ClientRequestWriterFunc(func(_ runtime.ClientRequest, _ strfmt.Registry) error {
return nil
})

Expand Down Expand Up @@ -287,7 +287,7 @@ func TestRuntime_CSVCanary(t *testing.T) {
}))
defer server.Close()

rwrtr := runtime.ClientRequestWriterFunc(func(req runtime.ClientRequest, _ strfmt.Registry) error {
rwrtr := runtime.ClientRequestWriterFunc(func(_ runtime.ClientRequest, _ strfmt.Registry) error {
return nil
})

Expand Down Expand Up @@ -325,7 +325,7 @@ func (fn roundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error)
}

func TestRuntime_CustomTransport(t *testing.T) {
rwrtr := runtime.ClientRequestWriterFunc(func(req runtime.ClientRequest, _ strfmt.Registry) error {
rwrtr := runtime.ClientRequestWriterFunc(func(_ runtime.ClientRequest, _ strfmt.Registry) error {
return nil
})
result := []task{
Expand Down Expand Up @@ -402,7 +402,7 @@ func TestRuntime_CustomCookieJar(t *testing.T) {
}))
defer server.Close()

rwrtr := runtime.ClientRequestWriterFunc(func(req runtime.ClientRequest, _ strfmt.Registry) error {
rwrtr := runtime.ClientRequestWriterFunc(func(_ runtime.ClientRequest, _ strfmt.Registry) error {
return nil
})

Expand Down Expand Up @@ -457,7 +457,7 @@ func TestRuntime_AuthCanary(t *testing.T) {
}))
defer server.Close()

rwrtr := runtime.ClientRequestWriterFunc(func(req runtime.ClientRequest, _ strfmt.Registry) error {
rwrtr := runtime.ClientRequestWriterFunc(func(_ runtime.ClientRequest, _ strfmt.Registry) error {
return nil
})

Expand Down Expand Up @@ -559,7 +559,7 @@ func TestRuntime_ContentTypeCanary(t *testing.T) {
}))
defer server.Close()

rwrtr := runtime.ClientRequestWriterFunc(func(req runtime.ClientRequest, _ strfmt.Registry) error {
rwrtr := runtime.ClientRequestWriterFunc(func(_ runtime.ClientRequest, _ strfmt.Registry) error {
return nil
})

Expand Down Expand Up @@ -613,7 +613,7 @@ func TestRuntime_ChunkedResponse(t *testing.T) {
}))
defer server.Close()

rwrtr := runtime.ClientRequestWriterFunc(func(req runtime.ClientRequest, _ strfmt.Registry) error {
rwrtr := runtime.ClientRequestWriterFunc(func(_ runtime.ClientRequest, _ strfmt.Registry) error {
return nil
})

Expand Down Expand Up @@ -728,7 +728,7 @@ func TestRuntime_OverrideClientOperation(t *testing.T) {

_, err := rt.Submit(&runtime.ClientOperation{
Client: client2,
Params: runtime.ClientRequestWriterFunc(func(r runtime.ClientRequest, _ strfmt.Registry) error {
Params: runtime.ClientRequestWriterFunc(func(_ runtime.ClientRequest, _ strfmt.Registry) error {
return nil
}),
Reader: runtime.ClientResponseReaderFunc(func(_ runtime.ClientResponse, _ runtime.Consumer) (interface{}, error) {
Expand Down Expand Up @@ -759,7 +759,7 @@ func TestRuntime_PreserveTrailingSlash(t *testing.T) {
require.NoError(t, err)

rt := New(hu.Host, "/", []string{schemeHTTP})
rwrtr := runtime.ClientRequestWriterFunc(func(req runtime.ClientRequest, _ strfmt.Registry) error {
rwrtr := runtime.ClientRequestWriterFunc(func(_ runtime.ClientRequest, _ strfmt.Registry) error {
return nil
})

Expand Down Expand Up @@ -1200,7 +1200,7 @@ func TestRuntime_Timeout(t *testing.T) { //nolint:maintidx // linter evaluates t
})
})
t.Run("with no context, request uses the default timeout", func(t *testing.T) {
requestEmptyWriter := runtime.ClientRequestWriterFunc(func(req runtime.ClientRequest, _ strfmt.Registry) error {
requestEmptyWriter := runtime.ClientRequestWriterFunc(func(_ runtime.ClientRequest, _ strfmt.Registry) error {
return nil
})
host, cleaner := serverBuilder(t, serverDelay, result)
Expand Down
4 changes: 2 additions & 2 deletions client/runtime_tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestRuntimeTLSOptions(t *testing.T) {
})

t.Run("with TLSAuthConfig with VerifyPeer option", func(t *testing.T) {
verify := func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error {
verify := func(_ [][]byte, _ [][]*x509.Certificate) error {
return nil
}

Expand Down Expand Up @@ -156,7 +156,7 @@ func TestRuntimeManualCertificateValidation(t *testing.T) {
ID: "getTasks",
Method: http.MethodGet,
PathPattern: "/",
Params: runtime.ClientRequestWriterFunc(func(req runtime.ClientRequest, _ strfmt.Registry) error {
Params: runtime.ClientRequestWriterFunc(func(_ runtime.ClientRequest, _ strfmt.Registry) error {
return nil
}),
Reader: runtime.ClientResponseReaderFunc(func(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/testing/simplepetstore/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewPetstore() (http.Handler, error) {
return middleware.Serve(spec, api), nil
}

var getAllPets = runtime.OperationHandlerFunc(func(data interface{}) (interface{}, error) {
var getAllPets = runtime.OperationHandlerFunc(func(_ interface{}) (interface{}, error) {
return pets, nil
})

Expand Down
7 changes: 4 additions & 3 deletions middleware/denco/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package denco

import (
"errors"
"fmt"
"sort"
"strings"
Expand Down Expand Up @@ -71,7 +72,7 @@ func (rt *Router) Lookup(path string) (data interface{}, params Params, found bo
func (rt *Router) Build(records []Record) error {
statics, params := makeRecords(records)
if len(params) > MaxSize {
return fmt.Errorf("denco: too many records")
return errors.New("denco: too many records")
}
if rt.SizeHint < 0 {
rt.SizeHint = 0
Expand Down Expand Up @@ -331,7 +332,7 @@ func (da *doubleArray) arrange(records []*record, idx, depth int, usedBase map[i
}
base = da.findBase(siblings, idx, usedBase)
if base > MaxSize {
return -1, nil, nil, fmt.Errorf("denco: too many elements of internal slice")
return -1, nil, nil, errors.New("denco: too many elements of internal slice")
}
da.setBase(idx, base)
return base, siblings, leaf, err
Expand Down Expand Up @@ -392,7 +393,7 @@ func makeSiblings(records []*record, depth int) (sib []sibling, leaf *record, er
case pc == c:
continue
default:
return nil, nil, fmt.Errorf("denco: BUG: routing table hasn't been sorted")
return nil, nil, errors.New("denco: BUG: routing table hasn't been sorted")
}
if n > 0 {
sib[n-1].end = i
Expand Down
4 changes: 2 additions & 2 deletions middleware/operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

func TestOperationExecutor(t *testing.T) {
spec, api := petstore.NewAPI(t)
api.RegisterOperation("get", "/pets", runtime.OperationHandlerFunc(func(params interface{}) (interface{}, error) {
api.RegisterOperation("get", "/pets", runtime.OperationHandlerFunc(func(_ interface{}) (interface{}, error) {
return []interface{}{
map[string]interface{}{"id": 1, "name": "a dog"},
}, nil
Expand All @@ -49,7 +49,7 @@ func TestOperationExecutor(t *testing.T) {
assert.Equal(t, `[{"id":1,"name":"a dog"}]`+"\n", recorder.Body.String())

spec, api = petstore.NewAPI(t)
api.RegisterOperation("get", "/pets", runtime.OperationHandlerFunc(func(params interface{}) (interface{}, error) {
api.RegisterOperation("get", "/pets", runtime.OperationHandlerFunc(func(_ interface{}) (interface{}, error) {
return nil, errors.New(http.StatusUnprocessableEntity, "expected")
}))

Expand Down
4 changes: 2 additions & 2 deletions middleware/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ func TestRequestBindingDefaultValue(t *testing.T) {
assert.Equal(t, delivered, data["delivered"])
assert.Equal(t, confirmed, data["confirmed"])
assert.Equal(t, age, data["age"])
assert.Equal(t, factor, data["factor"])
assert.Equal(t, score, data["score"])
assert.InDelta(t, factor, data["factor"], 1e-6)
assert.InDelta(t, score, data["score"], 1e-6)
assert.Equal(t, "hello", string(data["picture"].(strfmt.Base64)))
}

Expand Down
4 changes: 2 additions & 2 deletions middleware/untyped_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ func TestUntypedBindingTypesForValid(t *testing.T) {
assert.Equal(t, delivered, data["delivered"])
assert.Equal(t, confirmed, data["confirmed"])
assert.Equal(t, age, data["age"])
assert.Equal(t, factor, data["factor"])
assert.Equal(t, score, data["score"])
assert.InDelta(t, factor, data["factor"], 1e-6)
assert.InDelta(t, score, data["score"], 1e-6)
pb, err := base64.URLEncoding.DecodeString(picture)
require.NoError(t, err)
assert.EqualValues(t, pb, data["picture"].(strfmt.Base64))
Expand Down
16 changes: 8 additions & 8 deletions security/apikey_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestApiKeyAuth(t *testing.T) {

ok, usr, err := ta.Authenticate(req)
assert.True(t, ok)
assert.Equal(t, nil, usr)
assert.Nil(t, usr)
require.Error(t, err)
})

Expand All @@ -73,7 +73,7 @@ func TestApiKeyAuth(t *testing.T) {

ok, usr, err := ta.Authenticate(req)
assert.False(t, ok)
assert.Equal(t, nil, usr)
assert.Nil(t, usr)
require.NoError(t, err)
})
})
Expand All @@ -99,7 +99,7 @@ func TestApiKeyAuth(t *testing.T) {

ok, usr, err := ta.Authenticate(req)
assert.True(t, ok)
assert.Equal(t, nil, usr)
assert.Nil(t, usr)
require.Error(t, err)
})

Expand All @@ -110,7 +110,7 @@ func TestApiKeyAuth(t *testing.T) {

ok, usr, err := ta.Authenticate(req)
assert.False(t, ok)
assert.Equal(t, nil, usr)
assert.Nil(t, usr)
require.NoError(t, err)
})
})
Expand Down Expand Up @@ -150,7 +150,7 @@ func TestApiKeyAuthCtx(t *testing.T) {
require.NoError(t, err)
ok, usr, err := ta.Authenticate(req)
assert.True(t, ok)
assert.Equal(t, nil, usr)
assert.Nil(t, usr)
require.Error(t, err)

assert.Equal(t, wisdom, req.Context().Value(original))
Expand All @@ -165,7 +165,7 @@ func TestApiKeyAuthCtx(t *testing.T) {

ok, usr, err := ta.Authenticate(req)
assert.False(t, ok)
assert.Equal(t, nil, usr)
assert.Nil(t, usr)
require.NoError(t, err)

assert.Equal(t, wisdom, req.Context().Value(original))
Expand Down Expand Up @@ -199,7 +199,7 @@ func TestApiKeyAuthCtx(t *testing.T) {

ok, usr, err := ta.Authenticate(req)
assert.True(t, ok)
assert.Equal(t, nil, usr)
assert.Nil(t, usr)
require.Error(t, err)

assert.Equal(t, wisdom, req.Context().Value(original))
Expand All @@ -213,7 +213,7 @@ func TestApiKeyAuthCtx(t *testing.T) {

ok, usr, err := ta.Authenticate(req)
assert.False(t, ok)
assert.Equal(t, nil, usr)
assert.Nil(t, usr)
require.NoError(t, err)

assert.Equal(t, wisdom, req.Context().Value(original))
Expand Down
4 changes: 2 additions & 2 deletions security/basic_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestBasicAuth(t *testing.T) {
ok, usr, err := ba.Authenticate(req)
require.NoError(t, err)
assert.False(t, ok)
assert.Equal(t, nil, usr)
assert.Nil(t, usr)

assert.NotEmpty(t, FailedBasicAuth(req))
assert.Equal(t, DefaultRealmName, FailedBasicAuth(req))
Expand Down Expand Up @@ -169,7 +169,7 @@ func TestBasicAuthCtx(t *testing.T) {
ok, usr, err := ba.Authenticate(req)
require.NoError(t, err)
assert.False(t, ok)
assert.Equal(t, nil, usr)
assert.Nil(t, usr)

assert.Equal(t, wisdom, req.Context().Value(original))
assert.Nil(t, req.Context().Value(extra))
Expand Down

0 comments on commit 35b5892

Please sign in to comment.