Files
openai/internal/form_builder_test.go
zeekayandHanzo Dev 88762272c3 refactor(module): declare own import path github.com/hanzoai/go-openai
The fork kept the upstream module path (module github.com/sashabaranov/
go-openai), so every consumer could only reach it through a
"replace github.com/sashabaranov/go-openai => github.com/hanzoai/go-openai"
directive — and Go replace directives do NOT propagate to consumers, so each
downstream repo had to copy the same replace or fail to compile against
fork-only fields (e.g. ReasoningContent). That is the opposite of one-and-
only-one-way.

Declare the fork's OWN module path so it can be required directly and inherited
transitively. Package name stays 'openai' (import identifier unchanged); only
the module path + internal self-imports (/internal, /jsonschema) are renamed.
Upstream issue-URL comments are left intact as attribution. Builds + vets clean.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-17 21:55:51 -07:00

46 lines
1.2 KiB
Go

package openai //nolint:testpackage // testing private field
import (
"github.com/hanzoai/go-openai/internal/test/checks"
"bytes"
"errors"
"os"
"testing"
)
type failingWriter struct {
}
var errMockFailingWriterError = errors.New("mock writer failed")
func (*failingWriter) Write([]byte) (int, error) {
return 0, errMockFailingWriterError
}
func TestFormBuilderWithFailingWriter(t *testing.T) {
file, err := os.CreateTemp(t.TempDir(), "")
if err != nil {
t.Fatalf("Error creating tmp file: %v", err)
}
defer file.Close()
builder := NewFormBuilder(&failingWriter{})
err = builder.CreateFormFile("file", file)
checks.ErrorIs(t, err, errMockFailingWriterError, "formbuilder should return error if writer fails")
}
func TestFormBuilderWithClosedFile(t *testing.T) {
file, err := os.CreateTemp(t.TempDir(), "")
if err != nil {
t.Fatalf("Error creating tmp file: %v", err)
}
file.Close()
body := &bytes.Buffer{}
builder := NewFormBuilder(body)
err = builder.CreateFormFile("file", file)
checks.HasError(t, err, "formbuilder should return error if file is closed")
checks.ErrorIs(t, err, os.ErrClosed, "formbuilder should return error if file is closed")
}