Skip to content

Commit

Permalink
テストを修正する
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexa committed Feb 13, 2024
1 parent 5ffce28 commit 2a4f84d
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions test_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2a4f84d

Please sign in to comment.