detached 3653243

Test Vertex endpoint selection

commit
365324343f51d6e652d85ab65bfddb4c501223d9
author
patriceckhart · · 2026-07-12 14:22 UTC
parent
28b802b
signature
unsigned
1 file · +50 -0
M packages/provider/google_vertex_test.go +50 -0
@@ -1,6 +1,7 @@
11 package provider
22
33 import (
4+ "net/http"
45 "os"
56 "path/filepath"
67 "testing"
@@ -40,6 +41,55 @@ func TestVertexConfigParsesAuthorizedUser(t *testing.T) {
4041 }
4142 }
4243
44+type vertexRoundTripFunc func(*http.Request) (*http.Response, error)
45+
46+func (f vertexRoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {
47+ return f(req)
48+}
49+
50+func TestVertexTransportEndpoint(t *testing.T) {
51+ tests := []struct {
52+ name string
53+ location string
54+ wantHost string
55+ }{
56+ {name: "global", location: "global", wantHost: "aiplatform.googleapis.com"},
57+ {name: "regional", location: "us-central1", wantHost: "us-central1-aiplatform.googleapis.com"},
58+ }
59+
60+ for _, tt := range tests {
61+ t.Run(tt.name, func(t *testing.T) {
62+ var got *http.Request
63+ transport := &vertexTransport{
64+ cfg: &vertexConfig{
65+ project: "test-project",
66+ location: tt.location,
67+ apiKey: "test-key",
68+ },
69+ inner: vertexRoundTripFunc(func(req *http.Request) (*http.Response, error) {
70+ got = req
71+ return &http.Response{StatusCode: http.StatusOK}, nil
72+ }),
73+ }
74+ req, err := http.NewRequest(http.MethodPost, "https://placeholder.example/v1beta/models/gemini-test:streamGenerateContent?alt=sse", nil)
75+ if err != nil {
76+ t.Fatal(err)
77+ }
78+
79+ if _, err := transport.RoundTrip(req); err != nil {
80+ t.Fatalf("RoundTrip: %v", err)
81+ }
82+ if got.URL.Host != tt.wantHost {
83+ t.Errorf("host = %q, want %q", got.URL.Host, tt.wantHost)
84+ }
85+ wantPath := "/v1/projects/test-project/locations/" + tt.location + "/publishers/google/models/gemini-test:streamGenerateContent"
86+ if got.URL.Path != wantPath {
87+ t.Errorf("path = %q, want %q", got.URL.Path, wantPath)
88+ }
89+ })
90+ }
91+}
92+
4393 func TestVertexConfigRejectsBadType(t *testing.T) {
4494 tmp := t.TempDir()
4595 path := filepath.Join(tmp, "adc.json")
@@ -1,6 +1,7 @@
1 package provider1 package provider
2 2
3 import (3 import (
4+ "net/http"
4 "os"5 "os"
5 "path/filepath"6 "path/filepath"
6 "testing"7 "testing"
@@ -40,6 +41,55 @@ func TestVertexConfigParsesAuthorizedUser(t *testing.T) {
40 }41 }
41 }42 }
42 43
44+type vertexRoundTripFunc func(*http.Request) (*http.Response, error)
45+
46+func (f vertexRoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {
47+ return f(req)
48+}
49+
50+func TestVertexTransportEndpoint(t *testing.T) {
51+ tests := []struct {
52+ name string
53+ location string
54+ wantHost string
55+ }{
56+ {name: "global", location: "global", wantHost: "aiplatform.googleapis.com"},
57+ {name: "regional", location: "us-central1", wantHost: "us-central1-aiplatform.googleapis.com"},
58+ }
59+
60+ for _, tt := range tests {
61+ t.Run(tt.name, func(t *testing.T) {
62+ var got *http.Request
63+ transport := &vertexTransport{
64+ cfg: &vertexConfig{
65+ project: "test-project",
66+ location: tt.location,
67+ apiKey: "test-key",
68+ },
69+ inner: vertexRoundTripFunc(func(req *http.Request) (*http.Response, error) {
70+ got = req
71+ return &http.Response{StatusCode: http.StatusOK}, nil
72+ }),
73+ }
74+ req, err := http.NewRequest(http.MethodPost, "https://placeholder.example/v1beta/models/gemini-test:streamGenerateContent?alt=sse", nil)
75+ if err != nil {
76+ t.Fatal(err)
77+ }
78+
79+ if _, err := transport.RoundTrip(req); err != nil {
80+ t.Fatalf("RoundTrip: %v", err)
81+ }
82+ if got.URL.Host != tt.wantHost {
83+ t.Errorf("host = %q, want %q", got.URL.Host, tt.wantHost)
84+ }
85+ wantPath := "/v1/projects/test-project/locations/" + tt.location + "/publishers/google/models/gemini-test:streamGenerateContent"
86+ if got.URL.Path != wantPath {
87+ t.Errorf("path = %q, want %q", got.URL.Path, wantPath)
88+ }
89+ })
90+ }
91+}
92+
43 func TestVertexConfigRejectsBadType(t *testing.T) {93 func TestVertexConfigRejectsBadType(t *testing.T) {
44 tmp := t.TempDir()94 tmp := t.TempDir()
45 path := filepath.Join(tmp, "adc.json")95 path := filepath.Join(tmp, "adc.json")

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 476

↑↓ moveenter openesc close