Skip to content

Commit 725538e

Browse files
authored
chore: use correct instance URI in tests (GoogleCloudPlatform#70)
1 parent c63b7b4 commit 725538e

File tree

4 files changed

+45
-45
lines changed

4 files changed

+45
-45
lines changed

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ the maximum time has passed. Defaults to 0s.`)
201201
func parseConfig(cmd *Command, conf *proxy.Config, args []string) error {
202202
// If no instance connection names were provided, error.
203203
if len(args) == 0 {
204-
return newBadCommandError("missing instance uri (e.g., /projects/$PROJECTS/locations/$LOCTION/clusters/$CLUSTER/instances/$INSTANCES)")
204+
return newBadCommandError("missing instance uri (e.g., projects/$PROJECTS/locations/$LOCTION/clusters/$CLUSTER/instances/$INSTANCES)")
205205
}
206206

207207
userHasSet := func(f string) bool {

cmd/root_test.go

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestNewCommandArguments(t *testing.T) {
4545
c.Instances = []proxy.InstanceConnConfig{{}}
4646
}
4747
if i := &c.Instances[0]; i.Name == "" {
48-
i.Name = "/projects/proj/locations/region/clusters/clust/instances/inst"
48+
i.Name = "projects/proj/locations/region/clusters/clust/instances/inst"
4949
}
5050
if c.APIEndpointURL == "" {
5151
c.APIEndpointURL = "https://alloydb.googleapis.com/v1beta"
@@ -59,56 +59,56 @@ func TestNewCommandArguments(t *testing.T) {
5959
}{
6060
{
6161
desc: "basic invocation with defaults",
62-
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst"},
62+
args: []string{"projects/proj/locations/region/clusters/clust/instances/inst"},
6363
want: withDefaults(&proxy.Config{
6464
Addr: "127.0.0.1",
65-
Instances: []proxy.InstanceConnConfig{{Name: "/projects/proj/locations/region/clusters/clust/instances/inst"}},
65+
Instances: []proxy.InstanceConnConfig{{Name: "projects/proj/locations/region/clusters/clust/instances/inst"}},
6666
}),
6767
},
6868
{
6969
desc: "using the address flag",
70-
args: []string{"--address", "0.0.0.0", "/projects/proj/locations/region/clusters/clust/instances/inst"},
70+
args: []string{"--address", "0.0.0.0", "projects/proj/locations/region/clusters/clust/instances/inst"},
7171
want: withDefaults(&proxy.Config{
7272
Addr: "0.0.0.0",
73-
Instances: []proxy.InstanceConnConfig{{Name: "/projects/proj/locations/region/clusters/clust/instances/inst"}},
73+
Instances: []proxy.InstanceConnConfig{{Name: "projects/proj/locations/region/clusters/clust/instances/inst"}},
7474
}),
7575
},
7676
{
7777
desc: "using the address (short) flag",
78-
args: []string{"-a", "0.0.0.0", "/projects/proj/locations/region/clusters/clust/instances/inst"},
78+
args: []string{"-a", "0.0.0.0", "projects/proj/locations/region/clusters/clust/instances/inst"},
7979
want: withDefaults(&proxy.Config{
8080
Addr: "0.0.0.0",
81-
Instances: []proxy.InstanceConnConfig{{Name: "/projects/proj/locations/region/clusters/clust/instances/inst"}},
81+
Instances: []proxy.InstanceConnConfig{{Name: "projects/proj/locations/region/clusters/clust/instances/inst"}},
8282
}),
8383
},
8484
{
8585
desc: "using the address query param",
86-
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?address=0.0.0.0"},
86+
args: []string{"projects/proj/locations/region/clusters/clust/instances/inst?address=0.0.0.0"},
8787
want: withDefaults(&proxy.Config{
8888
Addr: "127.0.0.1",
8989
Instances: []proxy.InstanceConnConfig{{
9090
Addr: "0.0.0.0",
91-
Name: "/projects/proj/locations/region/clusters/clust/instances/inst",
91+
Name: "projects/proj/locations/region/clusters/clust/instances/inst",
9292
}},
9393
}),
9494
},
9595
{
9696
desc: "using the port flag",
97-
args: []string{"--port", "6000", "/projects/proj/locations/region/clusters/clust/instances/inst"},
97+
args: []string{"--port", "6000", "projects/proj/locations/region/clusters/clust/instances/inst"},
9898
want: withDefaults(&proxy.Config{
9999
Port: 6000,
100100
}),
101101
},
102102
{
103103
desc: "using the port (short) flag",
104-
args: []string{"-p", "6000", "/projects/proj/locations/region/clusters/clust/instances/inst"},
104+
args: []string{"-p", "6000", "projects/proj/locations/region/clusters/clust/instances/inst"},
105105
want: withDefaults(&proxy.Config{
106106
Port: 6000,
107107
}),
108108
},
109109
{
110110
desc: "using the port query param",
111-
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?port=6000"},
111+
args: []string{"projects/proj/locations/region/clusters/clust/instances/inst?port=6000"},
112112
want: withDefaults(&proxy.Config{
113113
Instances: []proxy.InstanceConnConfig{{
114114
Port: 6000,
@@ -117,49 +117,49 @@ func TestNewCommandArguments(t *testing.T) {
117117
},
118118
{
119119
desc: "using the token flag",
120-
args: []string{"--token", "MYCOOLTOKEN", "/projects/proj/locations/region/clusters/clust/instances/inst"},
120+
args: []string{"--token", "MYCOOLTOKEN", "projects/proj/locations/region/clusters/clust/instances/inst"},
121121
want: withDefaults(&proxy.Config{
122122
Token: "MYCOOLTOKEN",
123123
}),
124124
},
125125
{
126126
desc: "using the token (short) flag",
127-
args: []string{"-t", "MYCOOLTOKEN", "/projects/proj/locations/region/clusters/clust/instances/inst"},
127+
args: []string{"-t", "MYCOOLTOKEN", "projects/proj/locations/region/clusters/clust/instances/inst"},
128128
want: withDefaults(&proxy.Config{
129129
Token: "MYCOOLTOKEN",
130130
}),
131131
},
132132
{
133133
desc: "using the credentiale file flag",
134-
args: []string{"--credentials-file", "/path/to/file", "/projects/proj/locations/region/clusters/clust/instances/inst"},
134+
args: []string{"--credentials-file", "/path/to/file", "projects/proj/locations/region/clusters/clust/instances/inst"},
135135
want: withDefaults(&proxy.Config{
136136
CredentialsFile: "/path/to/file",
137137
}),
138138
},
139139
{
140140
desc: "using the (short) credentiale file flag",
141-
args: []string{"-c", "/path/to/file", "/projects/proj/locations/region/clusters/clust/instances/inst"},
141+
args: []string{"-c", "/path/to/file", "projects/proj/locations/region/clusters/clust/instances/inst"},
142142
want: withDefaults(&proxy.Config{
143143
CredentialsFile: "/path/to/file",
144144
}),
145145
},
146146
{
147147
desc: "using the unix socket flag",
148-
args: []string{"--unix-socket", "/path/to/dir/", "/projects/proj/locations/region/clusters/clust/instances/inst"},
148+
args: []string{"--unix-socket", "/path/to/dir/", "projects/proj/locations/region/clusters/clust/instances/inst"},
149149
want: withDefaults(&proxy.Config{
150150
UnixSocket: "/path/to/dir/",
151151
}),
152152
},
153153
{
154154
desc: "using the (short) unix socket flag",
155-
args: []string{"-u", "/path/to/dir/", "/projects/proj/locations/region/clusters/clust/instances/inst"},
155+
args: []string{"-u", "/path/to/dir/", "projects/proj/locations/region/clusters/clust/instances/inst"},
156156
want: withDefaults(&proxy.Config{
157157
UnixSocket: "/path/to/dir/",
158158
}),
159159
},
160160
{
161161
desc: "using the unix socket query param",
162-
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?unix-socket=/path/to/dir/"},
162+
args: []string{"projects/proj/locations/region/clusters/clust/instances/inst?unix-socket=/path/to/dir/"},
163163
want: withDefaults(&proxy.Config{
164164
Instances: []proxy.InstanceConnConfig{{
165165
UnixSocket: "/path/to/dir/",
@@ -168,35 +168,35 @@ func TestNewCommandArguments(t *testing.T) {
168168
},
169169
{
170170
desc: "using the max connections flag",
171-
args: []string{"--max-connections", "1", "/projects/proj/locations/region/clusters/clust/instances/inst"},
171+
args: []string{"--max-connections", "1", "projects/proj/locations/region/clusters/clust/instances/inst"},
172172
want: withDefaults(&proxy.Config{
173173
MaxConnections: 1,
174174
}),
175175
},
176176
{
177177
desc: "using wait after signterm flag",
178-
args: []string{"--max-sigterm-delay", "10s", "/projects/proj/locations/region/clusters/clust/instances/inst"},
178+
args: []string{"--max-sigterm-delay", "10s", "projects/proj/locations/region/clusters/clust/instances/inst"},
179179
want: withDefaults(&proxy.Config{
180180
WaitOnClose: 10 * time.Second,
181181
}),
182182
},
183183
{
184184
desc: "enabling structured logging",
185-
args: []string{"--structured-logs", "/projects/proj/locations/region/clusters/clust/instances/inst"},
185+
args: []string{"--structured-logs", "projects/proj/locations/region/clusters/clust/instances/inst"},
186186
want: withDefaults(&proxy.Config{
187187
StructuredLogs: true,
188188
}),
189189
},
190190
{
191191
desc: "using the alloydbadmin-api-endpoint flag with the trailing slash",
192-
args: []string{"--alloydbadmin-api-endpoint", "https://test.googleapis.com/", "/projects/proj/locations/region/clusters/clust/instances/inst"},
192+
args: []string{"--alloydbadmin-api-endpoint", "https://test.googleapis.com/", "projects/proj/locations/region/clusters/clust/instances/inst"},
193193
want: withDefaults(&proxy.Config{
194194
APIEndpointURL: "https://test.googleapis.com",
195195
}),
196196
},
197197
{
198198
desc: "using the alloydbadmin-api-endpoint flag without the trailing slash",
199-
args: []string{"--alloydbadmin-api-endpoint", "https://test.googleapis.com", "/projects/proj/locations/region/clusters/clust/instances/inst"},
199+
args: []string{"--alloydbadmin-api-endpoint", "https://test.googleapis.com", "projects/proj/locations/region/clusters/clust/instances/inst"},
200200
want: withDefaults(&proxy.Config{
201201
APIEndpointURL: "https://test.googleapis.com",
202202
}),
@@ -238,12 +238,12 @@ func TestNewCommandWithGcloudAuth(t *testing.T) {
238238
}{
239239
{
240240
desc: "using the gcloud auth flag",
241-
args: []string{"--gcloud-auth", "/projects/proj/locations/region/clusters/clust/instances/inst"},
241+
args: []string{"--gcloud-auth", "projects/proj/locations/region/clusters/clust/instances/inst"},
242242
want: true,
243243
},
244244
{
245245
desc: "using the (short) gcloud auth flag",
246-
args: []string{"-g", "/projects/proj/locations/region/clusters/clust/instances/inst"},
246+
args: []string{"-g", "projects/proj/locations/region/clusters/clust/instances/inst"},
247247
want: true,
248248
},
249249
}
@@ -282,41 +282,41 @@ func TestNewCommandWithErrors(t *testing.T) {
282282
},
283283
{
284284
desc: "when the query string is bogus",
285-
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?%=foo"},
285+
args: []string{"projects/proj/locations/region/clusters/clust/instances/inst?%=foo"},
286286
},
287287
{
288288
desc: "when the address query param is empty",
289-
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?address="},
289+
args: []string{"projects/proj/locations/region/clusters/clust/instances/inst?address="},
290290
},
291291
{
292292
desc: "using the address flag with a bad IP address",
293-
args: []string{"--address", "bogus", "/projects/proj/locations/region/clusters/clust/instances/inst"},
293+
args: []string{"--address", "bogus", "projects/proj/locations/region/clusters/clust/instances/inst"},
294294
},
295295
{
296296
desc: "when the address query param is not an IP address",
297-
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?address=世界"},
297+
args: []string{"projects/proj/locations/region/clusters/clust/instances/inst?address=世界"},
298298
},
299299
{
300300
desc: "when the address query param contains multiple values",
301-
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?address=0.0.0.0&address=1.1.1.1&address=2.2.2.2"},
301+
args: []string{"projects/proj/locations/region/clusters/clust/instances/inst?address=0.0.0.0&address=1.1.1.1&address=2.2.2.2"},
302302
},
303303
{
304304
desc: "when the query string is invalid",
305-
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?address=1.1.1.1?foo=2.2.2.2"},
305+
args: []string{"projects/proj/locations/region/clusters/clust/instances/inst?address=1.1.1.1?foo=2.2.2.2"},
306306
},
307307
{
308308
desc: "when the port query param contains multiple values",
309-
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?port=1&port=2"},
309+
args: []string{"projects/proj/locations/region/clusters/clust/instances/inst?port=1&port=2"},
310310
},
311311
{
312312
desc: "when the port query param is not a number",
313-
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?port=hi"},
313+
args: []string{"projects/proj/locations/region/clusters/clust/instances/inst?port=hi"},
314314
},
315315
{
316316
desc: "when both token and credentials file are set",
317317
args: []string{
318318
"--token", "my-token",
319-
"--credentials-file", "/path/to/file", "/projects/proj/locations/region/clusters/clust/instances/inst"},
319+
"--credentials-file", "/path/to/file", "projects/proj/locations/region/clusters/clust/instances/inst"},
320320
},
321321
{
322322
desc: "when both token and gcloud auth are set",
@@ -332,23 +332,23 @@ func TestNewCommandWithErrors(t *testing.T) {
332332
},
333333
{
334334
desc: "when the unix socket query param contains multiple values",
335-
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?unix-socket=/one&unix-socket=/two"},
335+
args: []string{"projects/proj/locations/region/clusters/clust/instances/inst?unix-socket=/one&unix-socket=/two"},
336336
},
337337
{
338338
desc: "using the unix socket flag with addr",
339-
args: []string{"-u", "/path/to/dir/", "-a", "127.0.0.1", "/projects/proj/locations/region/clusters/clust/instances/inst"},
339+
args: []string{"-u", "/path/to/dir/", "-a", "127.0.0.1", "projects/proj/locations/region/clusters/clust/instances/inst"},
340340
},
341341
{
342342
desc: "using the unix socket flag with port",
343-
args: []string{"-u", "/path/to/dir/", "-p", "5432", "/projects/proj/locations/region/clusters/clust/instances/inst"},
343+
args: []string{"-u", "/path/to/dir/", "-p", "5432", "projects/proj/locations/region/clusters/clust/instances/inst"},
344344
},
345345
{
346346
desc: "using the unix socket and addr query params",
347-
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?unix-socket=/path&address=127.0.0.1"},
347+
args: []string{"projects/proj/locations/region/clusters/clust/instances/inst?unix-socket=/path&address=127.0.0.1"},
348348
},
349349
{
350350
desc: "using the unix socket and port query params",
351-
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?unix-socket=/path&port=5000"},
351+
args: []string{"projects/proj/locations/region/clusters/clust/instances/inst?unix-socket=/path&port=5000"},
352352
},
353353
{
354354
desc: "enabling a Prometheus port without a namespace",

internal/proxy/proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func (c *portConfig) nextPort() int {
148148

149149
var (
150150
// Instance URI is in the format:
151-
// '/projects/<PROJECT>/locations/<REGION>/clusters/<CLUSTER>/instances/<INSTANCE>'
151+
// 'projects/<PROJECT>/locations/<REGION>/clusters/<CLUSTER>/instances/<INSTANCE>'
152152
// Additionally, we have to support legacy "domain-scoped" projects (e.g. "google.com:PROJECT")
153153
instURIRegex = regexp.MustCompile("projects/([^:]+(:[^:]+)?)/locations/([^:]+)/clusters/([^:]+)/instances/([^:]+)")
154154
)

internal/proxy/proxy_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ func TestClientInitialization(t *testing.T) {
8787
ctx := context.Background()
8888
testDir, cleanup := createTempDir(t)
8989
defer cleanup()
90-
inst1 := "/projects/proj/locations/region/clusters/clust/instances/inst1"
91-
inst2 := "/projects/proj/locations/region/clusters/clust/instances/inst2"
90+
inst1 := "projects/proj/locations/region/clusters/clust/instances/inst1"
91+
inst2 := "projects/proj/locations/region/clusters/clust/instances/inst2"
9292
wantUnix := "proj.region.clust.inst1"
9393

9494
tcs := []testCase{
@@ -445,7 +445,7 @@ func TestClientInitializationWorksRepeatedly(t *testing.T) {
445445
in := &proxy.Config{
446446
UnixSocket: testDir,
447447
Instances: []proxy.InstanceConnConfig{
448-
{Name: "/projects/proj/locations/region/clusters/clust/instances/inst1"},
448+
{Name: "projects/proj/locations/region/clusters/clust/instances/inst1"},
449449
},
450450
}
451451
logger := log.NewStdLogger(os.Stdout, os.Stdout)

0 commit comments

Comments
 (0)