From 3bc187e68ee01dbb4f1ecfb45dadf3c86179d88d Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Mon, 19 Jun 2023 22:55:12 +0900 Subject: [PATCH] check the errors --- ridgenative.go | 4 ++-- ridgenative_test.go | 24 ++++++++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/ridgenative.go b/ridgenative.go index 5ba49f5..cf52a18 100644 --- a/ridgenative.go +++ b/ridgenative.go @@ -574,9 +574,9 @@ func (f *lambdaFunction) lambdaHandlerStreaming(ctx context.Context, req *reques rw := newStreamingResponseWriter(w) defer func() { if v := recover(); v != nil { - rw.closeWithError(lambdaPanicResponse(v)) + _ = rw.closeWithError(lambdaPanicResponse(v)) } else { - rw.close() + _ = rw.close() } }() f.mux.ServeHTTP(rw, r) diff --git a/ridgenative_test.go b/ridgenative_test.go index 6faf92c..787e497 100644 --- a/ridgenative_test.go +++ b/ridgenative_test.go @@ -762,7 +762,9 @@ func TestLambdaHandlerStreaming(t *testing.T) { t.Run("normal", func(t *testing.T) { l := newLambdaFunction(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - io.WriteString(w, `{"hello":"world"}`) + if _, err := io.WriteString(w, `{"hello":"world"}`); err != nil { + t.Error(err) + } })) r, w := io.Pipe() contentType, err := l.lambdaHandlerStreaming(context.Background(), &request{ @@ -794,8 +796,12 @@ func TestLambdaHandlerStreaming(t *testing.T) { // Writes to ResponseWriter are buffered, // so multiple writes to ResponseWriter become a single write to the pipe - io.WriteString(w, `{"hello":`) - io.WriteString(w, `"world"}`) + if _, err := io.WriteString(w, `{"hello":`); err != nil { + t.Error(err) + } + if _, err := io.WriteString(w, `"world"}`); err != nil { + t.Error(err) + } })) r, w := io.Pipe() contentType, err := l.lambdaHandlerStreaming(context.Background(), &request{ @@ -851,9 +857,13 @@ func TestLambdaHandlerStreaming(t *testing.T) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) - io.WriteString(w, `{"hello":`) + if _, err := io.WriteString(w, `{"hello":`); err != nil { + t.Error(err) + } f.Flush() - io.WriteString(w, `"world"}`) + if _, err := io.WriteString(w, `"world"}`); err != nil { + t.Error(err) + } })) r, w := io.Pipe() contentType, err := l.lambdaHandlerStreaming(context.Background(), &request{ @@ -911,7 +921,9 @@ func TestLambdaHandlerStreaming(t *testing.T) { t.Run("detect content-type", func(t *testing.T) { l := newLambdaFunction(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - io.WriteString(w, ``) + if _, err := io.WriteString(w, ``); err != nil { + t.Error(err) + } })) r, w := io.Pipe() contentType, err := l.lambdaHandlerStreaming(context.Background(), &request{