* move error_accumulator into internal pkg (#304) * move error_accumulator into internal pkg (#304) * add a test for ErrTooManyEmptyStreamMessages in stream_reader (#304)
This commit is contained in:
committed by
GitHub
parent
fa694c61c2
commit
1394329e44
41
internal/error_accumulator_test.go
Normal file
41
internal/error_accumulator_test.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package openai_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
utils "github.com/sashabaranov/go-openai/internal"
|
||||
"github.com/sashabaranov/go-openai/internal/test"
|
||||
)
|
||||
|
||||
func TestErrorAccumulatorBytes(t *testing.T) {
|
||||
accumulator := &utils.DefaultErrorAccumulator{
|
||||
Buffer: &bytes.Buffer{},
|
||||
}
|
||||
|
||||
errBytes := accumulator.Bytes()
|
||||
if len(errBytes) != 0 {
|
||||
t.Fatalf("Did not return nil with empty bytes: %s", string(errBytes))
|
||||
}
|
||||
|
||||
err := accumulator.Write([]byte("{}"))
|
||||
if err != nil {
|
||||
t.Fatalf("%+v", err)
|
||||
}
|
||||
|
||||
errBytes = accumulator.Bytes()
|
||||
if len(errBytes) == 0 {
|
||||
t.Fatalf("Did not return error bytes when has error: %s", string(errBytes))
|
||||
}
|
||||
}
|
||||
|
||||
func TestErrorByteWriteErrors(t *testing.T) {
|
||||
accumulator := &utils.DefaultErrorAccumulator{
|
||||
Buffer: &test.FailingErrorBuffer{},
|
||||
}
|
||||
err := accumulator.Write([]byte("{"))
|
||||
if !errors.Is(err, test.ErrTestErrorAccumulatorWriteFailed) {
|
||||
t.Fatalf("Did not return error when write failed: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user