Skip to content

Commit 78e454b

Browse files
committed
fixup! fix(transport): header override, gzip pool, body-read error, and body-close correctness (opensearch-project#859)
Signed-off-by: Sean Chittenden <sean.chittenden@crowdstrike.com>
1 parent bd7bea3 commit 78e454b

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

response_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ package opensearch_test
2323

2424
import (
2525
"errors"
26+
"fmt"
2627
"io"
2728
"net/http"
2829
"strings"
@@ -34,6 +35,20 @@ import (
3435
"github.com/opensearch-project/opensearch-go/v5"
3536
)
3637

38+
// String uses a pointer receiver because it is non-consuming: it restores Body
39+
// after rendering, which mutates the receiver. Consequently only *Response
40+
// satisfies fmt.Stringer; a Response value deliberately does not, so passing a
41+
// value to fmt.Print*/Sprintf("%s", ...) is a mistake the compiler cannot catch.
42+
// This guard pins the pointer contract; TestResponseValueNotStringer pins the
43+
// value gap so a revert to a value receiver fails the build.
44+
var _ fmt.Stringer = (*opensearch.Response)(nil)
45+
46+
func TestResponseValueNotStringer(t *testing.T) {
47+
var v any = opensearch.Response{}
48+
_, ok := v.(fmt.Stringer)
49+
require.False(t, ok, "Response value must not satisfy fmt.Stringer; String() is pointer-receiver on v5")
50+
}
51+
3752
func TestResponse(t *testing.T) {
3853
t.Run("empty response", func(t *testing.T) {
3954
resp := opensearch.NewResponse(0, nil, nil)

0 commit comments

Comments
 (0)