forked from sashabaranov/go-openai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_accumulator_test.go
41 lines (34 loc) · 950 Bytes
/
error_accumulator_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package openai_test
import (
"bytes"
"errors"
"testing"
utils "github.com/joel29dec/go-openai/internal"
"github.com/joel29dec/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)
}
}