diff --git a/.golangci.yml b/.golangci.yml index 2f9b8162..eece6318 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -50,6 +50,7 @@ linters: - lll # don't want hard limits for line length - maintidx # covered by gocyclo - maligned # readability trumps efficient struct packing + - mnd # status codes are clearer than constants - nlreturn # generous whitespace violates house style - nonamedreturns # named returns are fine; it's *bare* returns that are bad - nosnakecase # deprecated in https://github.com/golangci/golangci-lint/pull/3065 @@ -64,7 +65,7 @@ issues: exclude: # Don't ban use of fmt.Errorf to create new errors, but the remaining # checks from err113 are useful. - - "err113: do not define dynamic errors.*" + - "do not define dynamic errors, use wrapped static errors instead: .*" exclude-rules: # If future reflect.Kinds are nil-able, we'll find out when a test fails. @@ -129,3 +130,6 @@ issues: # Allow fmt.Sprintf for cmd/protoc-gen-connect-go for consistency - linters: [perfsprint] path: cmd/protoc-gen-connect-go/main.go + # Allow non-canonical headers in tests + - linters: [canonicalheader] + path: protocol_grpc_test.go diff --git a/client_stream_test.go b/client_stream_test.go index a812caa1..cf072392 100644 --- a/client_stream_test.go +++ b/client_stream_test.go @@ -95,8 +95,8 @@ func verifyHeaders(t *testing.T, headers http.Header) { assert.Equal(t, headers, http.Header{}) // Verify set/del don't panic - headers.Set("a", "b") - headers.Del("a") + headers.Set("A", "b") + headers.Del("A") } type nopStreamingClientConn struct { diff --git a/error_test.go b/error_test.go index 93306a9c..3535b0b0 100644 --- a/error_test.go +++ b/error_test.go @@ -39,8 +39,8 @@ func TestErrorNilUnderlying(t *testing.T) { err.AddDetail(detail) assert.Equal(t, len(err.Details()), 1) assert.Equal(t, err.Details()[0].Type(), "google.protobuf.Empty") - err.Meta().Set("foo", "bar") - assert.Equal(t, err.Meta().Get("foo"), "bar") + err.Meta().Set("Foo", "bar") + assert.Equal(t, err.Meta().Get("Foo"), "bar") assert.Equal(t, CodeOf(err), CodeUnknown) } @@ -51,9 +51,9 @@ func TestErrorFormatting(t *testing.T) { NewError(CodeUnavailable, errors.New("")).Error(), CodeUnavailable.String(), ) - got := NewError(CodeUnavailable, errors.New("foo")).Error() + got := NewError(CodeUnavailable, errors.New("Foo")).Error() assert.True(t, strings.Contains(got, CodeUnavailable.String())) - assert.True(t, strings.Contains(got, "foo")) + assert.True(t, strings.Contains(got, "Foo")) } func TestErrorCode(t *testing.T) { diff --git a/protocol_connect.go b/protocol_connect.go index 26f18b06..45577d82 100644 --- a/protocol_connect.go +++ b/protocol_connect.go @@ -1018,7 +1018,8 @@ func (m *connectUnaryRequestMarshaler) marshalWithGet(message any) *Error { if !isTooBig { url := m.buildGetURL(data, false /* compressed */) if m.getURLMaxBytes <= 0 || len(url.String()) < m.getURLMaxBytes { - return m.writeWithGet(url) + m.writeWithGet(url) + return nil } if m.compressionPool == nil { if m.getUseFallback { @@ -1044,7 +1045,8 @@ func (m *connectUnaryRequestMarshaler) marshalWithGet(message any) *Error { } url := m.buildGetURL(compressed.Bytes(), true /* compressed */) if m.getURLMaxBytes <= 0 || len(url.String()) < m.getURLMaxBytes { - return m.writeWithGet(url) + m.writeWithGet(url) + return nil } if m.getUseFallback { setHeaderCanonical(m.header, connectUnaryHeaderCompression, m.compressionName) @@ -1071,14 +1073,13 @@ func (m *connectUnaryRequestMarshaler) buildGetURL(data []byte, compressed bool) return &url } -func (m *connectUnaryRequestMarshaler) writeWithGet(url *url.URL) *Error { +func (m *connectUnaryRequestMarshaler) writeWithGet(url *url.URL) { delHeaderCanonical(m.header, connectHeaderProtocolVersion) delHeaderCanonical(m.header, headerContentType) delHeaderCanonical(m.header, headerContentEncoding) delHeaderCanonical(m.header, headerContentLength) m.duplexCall.SetMethod(http.MethodGet) *m.duplexCall.URL() = *url - return nil } type connectUnaryUnmarshaler struct {