mirror of
https://github.com/hanzo-go/openai.git
synced 2026-09-24 00:31:39 +00:00
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]>
48 lines
1.5 KiB
Go
48 lines
1.5 KiB
Go
package openai_test
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/hanzoai/go-openai"
|
|
"github.com/hanzoai/go-openai/internal/test/checks"
|
|
)
|
|
|
|
// TestGetEngine Tests the retrieve engine endpoint of the API using the mocked server.
|
|
func TestGetEngine(t *testing.T) {
|
|
client, server, teardown := setupOpenAITestServer()
|
|
defer teardown()
|
|
server.RegisterHandler("/v1/engines/text-davinci-003", func(w http.ResponseWriter, _ *http.Request) {
|
|
resBytes, _ := json.Marshal(openai.Engine{})
|
|
fmt.Fprintln(w, string(resBytes))
|
|
})
|
|
_, err := client.GetEngine(context.Background(), "text-davinci-003")
|
|
checks.NoError(t, err, "GetEngine error")
|
|
}
|
|
|
|
// TestListEngines Tests the list engines endpoint of the API using the mocked server.
|
|
func TestListEngines(t *testing.T) {
|
|
client, server, teardown := setupOpenAITestServer()
|
|
defer teardown()
|
|
server.RegisterHandler("/v1/engines", func(w http.ResponseWriter, _ *http.Request) {
|
|
resBytes, _ := json.Marshal(openai.EnginesList{})
|
|
fmt.Fprintln(w, string(resBytes))
|
|
})
|
|
_, err := client.ListEngines(context.Background())
|
|
checks.NoError(t, err, "ListEngines error")
|
|
}
|
|
|
|
func TestListEnginesReturnError(t *testing.T) {
|
|
client, server, teardown := setupOpenAITestServer()
|
|
defer teardown()
|
|
server.RegisterHandler("/v1/engines", func(w http.ResponseWriter, _ *http.Request) {
|
|
w.WriteHeader(http.StatusTeapot)
|
|
})
|
|
|
|
_, err := client.ListEngines(context.Background())
|
|
checks.HasError(t, err, "ListEngines did not fail")
|
|
}
|