From 2a4f84d148f164adb4d8e8d86df9d95e0675765f Mon Sep 17 00:00:00 2001 From: Yoshida Hiroshi Date: Tue, 13 Feb 2024 13:19:57 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test_handler_test.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/test_handler_test.go b/test_handler_test.go index 05a33a0..57541ff 100644 --- a/test_handler_test.go +++ b/test_handler_test.go @@ -373,24 +373,32 @@ func TestSpeechHandler(t *testing.T) { c := e.NewContext(req, rec) h := s.createSpeechHandler(serviceType, func(ctx context.Context, w io.WriteCloser, chnanelID, connectionID, languageCode string, results any) error { - return fmt.Errorf("STREAM-ERROR") + go func() { + defer w.Close() + + encoder := json.NewEncoder(w) + if err := encoder.Encode(NewSuzuErrorResponse(fmt.Errorf("STREAM-ERROR"))); err != nil { + return + } + }() + + return nil }) err := h(c) - if assert.Error(t, err) { + if assert.NoError(t, err) { assert.Equal(t, http.StatusOK, rec.Code) delim := []byte("\n")[0] for { line, err := rec.Body.ReadBytes(delim) if err != nil { - if !assert.ErrorIs(t, err, io.EOF) { - t.Logf("STREAM-ERROR: %v\n", err) - } + assert.ErrorIs(t, err, io.EOF) break } + var result TranscriptionResult if err := json.Unmarshal(line, &result); err != nil { - t.Error(err) + assert.ErrorIs(t, err, io.EOF) } assert.Equal(t, "error", result.Type)