File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ package opensearch_test
2323
2424import (
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+
3752func TestResponse (t * testing.T ) {
3853 t .Run ("empty response" , func (t * testing.T ) {
3954 resp := opensearch .NewResponse (0 , nil , nil )
You can’t perform that action at this time.
0 commit comments