mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-04 16:35:27 +08:00
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package gemini
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
type openAIProxyStub struct {
|
|
status int
|
|
body string
|
|
}
|
|
|
|
func (s openAIProxyStub) ChatCompletions(w http.ResponseWriter, _ *http.Request) {
|
|
if s.status == 0 {
|
|
s.status = http.StatusOK
|
|
}
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(s.status)
|
|
_, _ = w.Write([]byte(s.body))
|
|
}
|
|
|
|
func TestGeminiProxyViaOpenAIVercelReleasePassthrough(t *testing.T) {
|
|
h := &Handler{OpenAI: openAIProxyStub{status: 200, body: `{"success":true}`}}
|
|
req := httptest.NewRequest(http.MethodPost, "/v1beta/models/gemini-2.5-pro:streamGenerateContent?__stream_release=1", strings.NewReader(`{"lease_id":"lease_123"}`))
|
|
rec := httptest.NewRecorder()
|
|
|
|
h.StreamGenerateContent(rec, req)
|
|
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("unexpected status: %d body=%s", rec.Code, rec.Body.String())
|
|
}
|
|
var out map[string]any
|
|
if err := json.Unmarshal(rec.Body.Bytes(), &out); err != nil {
|
|
t.Fatalf("expected json response, got err=%v body=%s", err, rec.Body.String())
|
|
}
|
|
if v, ok := out["success"].(bool); !ok || !v {
|
|
t.Fatalf("expected success=true passthrough, got=%v", out)
|
|
}
|
|
}
|