MCPcopy Create free account
hub / github.com/InferCore/InferCore / TestAdapter_InvokeNonStream

Function TestAdapter_InvokeNonStream

internal/adapters/gemini/gemini_test.go:15–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestAdapter_InvokeNonStream(t *testing.T) {
16 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
17 switch {
18 case r.Method == http.MethodGet && r.URL.Path == "/v1beta/models":
19 if r.Header.Get("x-goog-api-key") == "" {
20 w.WriteHeader(http.StatusUnauthorized)
21 return
22 }
23 w.WriteHeader(http.StatusOK)
24 case r.Method == http.MethodPost && strings.HasSuffix(r.URL.Path, ":generateContent"):
25 if r.Header.Get("x-goog-api-key") == "" {
26 w.WriteHeader(http.StatusUnauthorized)
27 return
28 }
29 w.Header().Set("Content-Type", "application/json")
30 _ = json.NewEncoder(w).Encode(map[string]any{
31 "candidates": []map[string]any{
32 {
33 "content": map[string]any{
34 "parts": []map[string]any{{"text": "hello gemini"}},
35 },
36 },
37 },
38 })
39 default:
40 http.NotFound(w, r)
41 }
42 }))
43 t.Cleanup(srv.Close)
44
45 a := New(config.BackendConfig{
46 Name: "g",
47 Type: "gemini",
48 Endpoint: srv.URL,
49 TimeoutMS: 5000,
50 APIKey: "k",
51 DefaultModel: "gemini-2.0-flash",
52 })
53
54 resp, err := a.Invoke(context.Background(), types.BackendRequest{
55 AIRequest: types.AIRequest{
56 Input: map[string]any{"text": "hi"},
57 },
58 })
59 if err != nil {
60 t.Fatalf("invoke: %v", err)
61 }
62 txt, _ := resp.Output["text"].(string)
63 if txt != "hello gemini" {
64 t.Fatalf("text: %q", txt)
65 }
66}
67
68func TestAdapter_InvokeVertexNonStream(t *testing.T) {
69 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 3

WriteHeaderMethod · 0.80
NewFunction · 0.70
InvokeMethod · 0.65

Tested by

no test coverage detected