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(lint): relinted #310

Merged
merged 2 commits into from
Mar 4, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@
"crypto/tls"
"crypto/x509"
"encoding/pem"
"errors"
"fmt"
"mime"
"net/http"
Expand Down Expand Up @@ -142,7 +143,7 @@
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")

Check warning on line 146 in client/runtime.go

View check run for this annotation

Codecov / codecov/patch

client/runtime.go#L146

Added line #L146 was not covered by tests
}

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
11 changes: 11 additions & 0 deletions internal/testing/data_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package testing

import (
"testing"

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

func TestInvalidJSON(t *testing.T) {
require.NotEmpty(t, InvalidJSONMessage)
}
14 changes: 14 additions & 0 deletions internal/testing/petstore/api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package petstore

import (
"testing"

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

func TestAPI(t *testing.T) {
doc, api := NewAPI(t)

require.NotNil(t, doc)
require.NotNil(t, api)
}
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
11 changes: 11 additions & 0 deletions logger/logger_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package logger

import (
"testing"

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

func TestLogger(t *testing.T) {
require.False(t, DebugEnabled())
}
2 changes: 2 additions & 0 deletions logger/standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"os"
)

var _ Logger = StandardLogger{}

type StandardLogger struct{}

func (StandardLogger) Printf(format string, args ...interface{}) {
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) 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")

Check warning on line 75 in middleware/denco/router.go

View check run for this annotation

Codecov / codecov/patch

middleware/denco/router.go#L75

Added line #L75 was not covered by tests
}
if rt.SizeHint < 0 {
rt.SizeHint = 0
Expand Down Expand Up @@ -331,7 +332,7 @@
}
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")

Check warning on line 335 in middleware/denco/router.go

View check run for this annotation

Codecov / codecov/patch

middleware/denco/router.go#L335

Added line #L335 was not covered by tests
}
da.setBase(idx, base)
return base, siblings, leaf, err
Expand Down Expand Up @@ -392,7 +393,7 @@
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")

Check warning on line 396 in middleware/denco/router.go

View check run for this annotation

Codecov / codecov/patch

middleware/denco/router.go#L396

Added line #L396 was not covered by tests
}
if n > 0 {
sib[n-1].end = i
Expand Down
16 changes: 16 additions & 0 deletions middleware/header/header_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package header

import (
"net/http"
"testing"

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

func TestHeader(t *testing.T) {
hdr := http.Header{
"x-test": []string{"value"},
}
clone := Copy(hdr)
require.Len(t, clone, len(hdr))
}
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