Refactor/internal testing (#194)
* added NoError check * corrected NoError * has error checks * replace more checks * Used checks test helper * Used checks test helper * remove duplicate import * fixed lint issues regarding length of messages --------- Co-authored-by: Rex Posadas <rposadas@redwoodlogistics.com>
This commit is contained in:
@@ -3,6 +3,7 @@ package openai_test
|
||||
import (
|
||||
. "github.com/sashabaranov/go-openai"
|
||||
"github.com/sashabaranov/go-openai/internal/test"
|
||||
"github.com/sashabaranov/go-openai/internal/test/checks"
|
||||
|
||||
"context"
|
||||
"errors"
|
||||
@@ -49,9 +50,7 @@ func TestCreateCompletionStream(t *testing.T) {
|
||||
dataBytes = append(dataBytes, []byte("data: [DONE]\n\n")...)
|
||||
|
||||
_, err := w.Write(dataBytes)
|
||||
if err != nil {
|
||||
t.Errorf("Write error: %s", err)
|
||||
}
|
||||
checks.NoError(t, err, "Write error")
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
@@ -74,9 +73,7 @@ func TestCreateCompletionStream(t *testing.T) {
|
||||
}
|
||||
|
||||
stream, err := client.CreateCompletionStream(ctx, request)
|
||||
if err != nil {
|
||||
t.Errorf("CreateCompletionStream returned error: %v", err)
|
||||
}
|
||||
checks.NoError(t, err, "CreateCompletionStream returned error")
|
||||
defer stream.Close()
|
||||
|
||||
expectedResponses := []CompletionResponse{
|
||||
@@ -138,9 +135,7 @@ func TestCreateCompletionStreamError(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err := w.Write(dataBytes)
|
||||
if err != nil {
|
||||
t.Errorf("Write error: %s", err)
|
||||
}
|
||||
checks.NoError(t, err, "Write error")
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
@@ -163,15 +158,12 @@ func TestCreateCompletionStreamError(t *testing.T) {
|
||||
}
|
||||
|
||||
stream, err := client.CreateCompletionStream(ctx, request)
|
||||
if err != nil {
|
||||
t.Errorf("CreateCompletionStream returned error: %v", err)
|
||||
}
|
||||
checks.NoError(t, err, "CreateCompletionStream returned error")
|
||||
defer stream.Close()
|
||||
|
||||
_, streamErr := stream.Recv()
|
||||
if streamErr == nil {
|
||||
t.Errorf("stream.Recv() did not return error")
|
||||
}
|
||||
checks.HasError(t, streamErr, "stream.Recv() did not return error")
|
||||
|
||||
var apiErr *APIError
|
||||
if !errors.As(streamErr, &apiErr) {
|
||||
t.Errorf("stream.Recv() did not return APIError")
|
||||
|
||||
Reference in New Issue
Block a user