feat: upload audio, get a private Swedish transcript, discuss it (#33, ADR-033) #39
@@ -9,6 +9,7 @@ import (
|
|||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@@ -238,3 +239,19 @@ func TestStatusError_ExposesItsCodeAsAKindAndNotItsSnippet(t *testing.T) {
|
|||||||
|
|
||||||
assert.Equal(t, "http_502", errkind.Of(err))
|
assert.Equal(t, "http_502", errkind.Of(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGateway_AnErrorBodyIsBoundedToTwoHundredBytesInTheStatusError(t *testing.T) {
|
||||||
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
_, _ = w.Write([]byte(strings.Repeat("x", 100_000)))
|
||||||
|
}))
|
||||||
|
defer srv.Close()
|
||||||
|
wav := filepath.Join(t.TempDir(), "a.wav")
|
||||||
|
require.NoError(t, os.WriteFile(wav, []byte("RIFF....WAVEfmt "), 0o600))
|
||||||
|
|
||||||
|
_, err := transcribe.NewGateway(srv.URL, "", "iguana/kb-whisper", srv.Client()).Transcribe(context.Background(), wav)
|
||||||
|
|
||||||
|
var se *transcribe.StatusError
|
||||||
|
require.ErrorAs(t, err, &se)
|
||||||
|
assert.LessOrEqual(t, len(se.Snippet), 200, "a gateway's whole body must not become part of an error")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user