Skip to content

Commit 447bd21

Browse files
committed
add EndpointURL to the tests and other places that should use it instead of Endpoint
1 parent 56882e2 commit 447bd21

File tree

6 files changed

+97
-18
lines changed

6 files changed

+97
-18
lines changed

cmd/src/login_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io"
88
"net/http"
99
"net/http/httptest"
10+
"net/url"
1011
"strings"
1112
"testing"
1213

@@ -63,7 +64,8 @@ func TestLogin(t *testing.T) {
6364
defer s.Close()
6465

6566
endpoint := s.URL
66-
out, err := check(t, &config{Endpoint: endpoint, AccessToken: "x"}, endpoint)
67+
u, _ := url.ParseRequestURI(endpoint)
68+
out, err := check(t, &config{Endpoint: endpoint, EndpointURL: u, AccessToken: "x"}, endpoint)
6769
if err != cmderrors.ExitCode1 {
6870
t.Fatal(err)
6971
}
@@ -82,7 +84,8 @@ func TestLogin(t *testing.T) {
8284
defer s.Close()
8385

8486
endpoint := s.URL
85-
out, err := check(t, &config{Endpoint: endpoint, AccessToken: "x"}, endpoint)
87+
u, _ := url.ParseRequestURI(endpoint)
88+
out, err := check(t, &config{Endpoint: endpoint, EndpointURL: u, AccessToken: "x"}, endpoint)
8689
if err != nil {
8790
t.Fatal(err)
8891
}

cmd/src/main_test.go

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ func TestReadConfig(t *testing.T) {
4242
{
4343
name: "defaults",
4444
want: &config{
45-
Endpoint: "https://sourcegraph.com",
45+
Endpoint: "https://sourcegraph.com",
46+
EndpointURL: &url.URL{
47+
Scheme: "https",
48+
Host: "sourcegraph.com",
49+
},
4650
AdditionalHeaders: map[string]string{},
4751
},
4852
},
@@ -54,7 +58,11 @@ func TestReadConfig(t *testing.T) {
5458
Proxy: "https://proxy.com:8080",
5559
},
5660
want: &config{
57-
Endpoint: "https://example.com",
61+
Endpoint: "https://example.com",
62+
EndpointURL: &url.URL{
63+
Scheme: "https",
64+
Host: "example.com",
65+
},
5866
AccessToken: "deadbeef",
5967
AdditionalHeaders: map[string]string{},
6068
Proxy: "https://proxy.com:8080",
@@ -95,6 +103,10 @@ func TestReadConfig(t *testing.T) {
95103
envProxy: "socks5://other.proxy.com:9999",
96104
want: &config{
97105
Endpoint: "https://example.com",
106+
EndpointURL: &url.URL{
107+
Scheme: "https",
108+
Host: "example.com",
109+
},
98110
AccessToken: "deadbeef",
99111
Proxy: "socks5://other.proxy.com:9999",
100112
ProxyPath: "",
@@ -117,6 +129,10 @@ func TestReadConfig(t *testing.T) {
117129
envProxy: "socks5://other.proxy.com:9999",
118130
want: &config{
119131
Endpoint: "https://override.com",
132+
EndpointURL: &url.URL{
133+
Scheme: "https",
134+
Host: "override.com",
135+
},
120136
AccessToken: "abc",
121137
Proxy: "socks5://other.proxy.com:9999",
122138
ProxyPath: "",
@@ -132,6 +148,10 @@ func TestReadConfig(t *testing.T) {
132148
envToken: "abc",
133149
want: &config{
134150
Endpoint: "https://sourcegraph.com",
151+
EndpointURL: &url.URL{
152+
Scheme: "https",
153+
Host: "sourcegraph.com",
154+
},
135155
AccessToken: "abc",
136156
AdditionalHeaders: map[string]string{},
137157
},
@@ -141,6 +161,10 @@ func TestReadConfig(t *testing.T) {
141161
envEndpoint: "https://example.com",
142162
want: &config{
143163
Endpoint: "https://example.com",
164+
EndpointURL: &url.URL{
165+
Scheme: "https",
166+
Host: "example.com",
167+
},
144168
AccessToken: "",
145169
AdditionalHeaders: map[string]string{},
146170
},
@@ -150,6 +174,10 @@ func TestReadConfig(t *testing.T) {
150174
envProxy: "https://proxy.com:8080",
151175
want: &config{
152176
Endpoint: "https://sourcegraph.com",
177+
EndpointURL: &url.URL{
178+
Scheme: "https",
179+
Host: "sourcegraph.com",
180+
},
153181
AccessToken: "",
154182
Proxy: "https://proxy.com:8080",
155183
ProxyPath: "",
@@ -167,6 +195,10 @@ func TestReadConfig(t *testing.T) {
167195
envProxy: "https://proxy.com:8080",
168196
want: &config{
169197
Endpoint: "https://example.com",
198+
EndpointURL: &url.URL{
199+
Scheme: "https",
200+
Host: "example.com",
201+
},
170202
AccessToken: "abc",
171203
Proxy: "https://proxy.com:8080",
172204
ProxyPath: "",
@@ -182,6 +214,10 @@ func TestReadConfig(t *testing.T) {
182214
envProxy: "unix://" + socketPath,
183215
want: &config{
184216
Endpoint: "https://sourcegraph.com",
217+
EndpointURL: &url.URL{
218+
Scheme: "https",
219+
Host: "sourcegraph.com",
220+
},
185221
Proxy: "unix://" + socketPath,
186222
ProxyPath: socketPath,
187223
ProxyURL: nil,
@@ -193,6 +229,10 @@ func TestReadConfig(t *testing.T) {
193229
envProxy: socketPath,
194230
want: &config{
195231
Endpoint: "https://sourcegraph.com",
232+
EndpointURL: &url.URL{
233+
Scheme: "https",
234+
Host: "sourcegraph.com",
235+
},
196236
Proxy: socketPath,
197237
ProxyPath: socketPath,
198238
ProxyURL: nil,
@@ -204,6 +244,10 @@ func TestReadConfig(t *testing.T) {
204244
envProxy: "socks://localhost:1080",
205245
want: &config{
206246
Endpoint: "https://sourcegraph.com",
247+
EndpointURL: &url.URL{
248+
Scheme: "https",
249+
Host: "sourcegraph.com",
250+
},
207251
Proxy: "socks://localhost:1080",
208252
ProxyPath: "",
209253
ProxyURL: &url.URL{
@@ -218,6 +262,10 @@ func TestReadConfig(t *testing.T) {
218262
envProxy: "socks5h://localhost:1080",
219263
want: &config{
220264
Endpoint: "https://sourcegraph.com",
265+
EndpointURL: &url.URL{
266+
Scheme: "https",
267+
Host: "sourcegraph.com",
268+
},
221269
Proxy: "socks5h://localhost:1080",
222270
ProxyPath: "",
223271
ProxyURL: &url.URL{
@@ -237,6 +285,10 @@ func TestReadConfig(t *testing.T) {
237285
},
238286
want: &config{
239287
Endpoint: "https://override.com",
288+
EndpointURL: &url.URL{
289+
Scheme: "https",
290+
Host: "override.com",
291+
},
240292
AccessToken: "deadbeef",
241293
AdditionalHeaders: map[string]string{},
242294
},
@@ -248,6 +300,10 @@ func TestReadConfig(t *testing.T) {
248300
envToken: "abc",
249301
want: &config{
250302
Endpoint: "https://override.com",
303+
EndpointURL: &url.URL{
304+
Scheme: "https",
305+
Host: "override.com",
306+
},
251307
AccessToken: "abc",
252308
AdditionalHeaders: map[string]string{},
253309
},
@@ -260,6 +316,10 @@ func TestReadConfig(t *testing.T) {
260316
envFooHeader: "bar",
261317
want: &config{
262318
Endpoint: "https://override.com",
319+
EndpointURL: &url.URL{
320+
Scheme: "https",
321+
Host: "override.com",
322+
},
263323
AccessToken: "abc",
264324
AdditionalHeaders: map[string]string{"foo": "bar"},
265325
},
@@ -272,6 +332,10 @@ func TestReadConfig(t *testing.T) {
272332
envHeaders: "foo:bar\nfoo-bar:bar-baz",
273333
want: &config{
274334
Endpoint: "https://override.com",
335+
EndpointURL: &url.URL{
336+
Scheme: "https",
337+
Host: "override.com",
338+
},
275339
AccessToken: "abc",
276340
AdditionalHeaders: map[string]string{"foo-bar": "bar-baz", "foo": "bar"},
277341
},

cmd/src/search_jobs.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func parseColumns(columnsFlag string) []string {
156156
// createSearchJobsClient creates a reusable API client for search jobs commands
157157
func createSearchJobsClient(out *flag.FlagSet, apiFlags *api.Flags) api.Client {
158158
return api.NewClient(api.ClientOpts{
159-
Endpoint: cfg.Endpoint,
159+
EndpointURL: cfg.EndpointURL,
160160
AccessToken: cfg.AccessToken,
161161
Out: out.Output(),
162162
Flags: apiFlags,
@@ -259,11 +259,11 @@ func init() {
259259
usage := `'src search-jobs' is a tool that manages search jobs on a Sourcegraph instance.
260260
261261
Usage:
262-
262+
263263
src search-jobs command [command options]
264-
264+
265265
The commands are:
266-
266+
267267
cancel cancels a search job by ID
268268
create creates a search job
269269
delete deletes a search job by ID
@@ -272,11 +272,11 @@ func init() {
272272
logs fetches logs for a search job by ID
273273
restart restarts a search job by ID
274274
results fetches results for a search job by ID
275-
275+
276276
Common options for all commands:
277277
-c Select columns to display (e.g., -c id,query,state,username)
278278
-json Output results in JSON format
279-
279+
280280
Use "src search-jobs [command] -h" for more information about a command.
281281
`
282282

cmd/src/search_stream_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net"
77
"net/http"
88
"net/http/httptest"
9+
"net/url"
910
"os"
1011
"testing"
1112

@@ -126,8 +127,10 @@ func TestSearchStream(t *testing.T) {
126127
s := testServer(t, http.HandlerFunc(mockStreamHandler))
127128
defer s.Close()
128129

130+
u, _ := url.ParseRequestURI(s.URL)
129131
cfg = &config{
130-
Endpoint: s.URL,
132+
Endpoint: s.URL,
133+
EndpointURL: u,
131134
}
132135
defer func() { cfg = nil }()
133136

internal/batches/executor/executor_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"net/http"
88
"net/http/httptest"
9+
"net/url"
910
"os"
1011
"path/filepath"
1112
"runtime"
@@ -406,7 +407,8 @@ func TestExecutor_Integration(t *testing.T) {
406407

407408
// Setup an api.Client that points to this test server
408409
var clientBuffer bytes.Buffer
409-
client := api.NewClient(api.ClientOpts{Endpoint: ts.URL, Out: &clientBuffer})
410+
u, _ := url.ParseRequestURI(ts.URL)
411+
client := api.NewClient(api.ClientOpts{EndpointURL: u, Out: &clientBuffer})
410412

411413
// Temp dir for log files and downloaded archives
412414
testTempDir := t.TempDir()
@@ -827,7 +829,8 @@ func testExecuteTasks(t *testing.T, tasks []*Task, archives ...mock.RepoArchive)
827829
t.Cleanup(ts.Close)
828830

829831
var clientBuffer bytes.Buffer
830-
client := api.NewClient(api.ClientOpts{Endpoint: ts.URL, Out: &clientBuffer})
832+
u, _ := url.ParseRequestURI(ts.URL)
833+
client := api.NewClient(api.ClientOpts{EndpointURL: u, Out: &clientBuffer})
831834

832835
// Prepare images
833836
//

internal/batches/repozip/fetcher_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"net/http"
77
"net/http/httptest"
8+
"net/url"
89
"os"
910
"path"
1011
"path/filepath"
@@ -44,7 +45,8 @@ func TestArchive_Ensure(t *testing.T) {
4445
defer ts.Close()
4546

4647
var clientBuffer bytes.Buffer
47-
client := api.NewClient(api.ClientOpts{Endpoint: ts.URL, Out: &clientBuffer})
48+
u, _ := url.ParseRequestURI(ts.URL)
49+
client := api.NewClient(api.ClientOpts{EndpointURL: u, Out: &clientBuffer})
4850

4951
rf := &archiveRegistry{
5052
client: client,
@@ -89,7 +91,8 @@ func TestArchive_Ensure(t *testing.T) {
8991
defer ts.Close()
9092

9193
var clientBuffer bytes.Buffer
92-
client := api.NewClient(api.ClientOpts{Endpoint: ts.URL, Out: &clientBuffer})
94+
u, _ := url.ParseRequestURI(ts.URL)
95+
client := api.NewClient(api.ClientOpts{EndpointURL: u, Out: &clientBuffer})
9396

9497
rf := &archiveRegistry{
9598
client: client,
@@ -153,7 +156,8 @@ func TestArchive_Ensure(t *testing.T) {
153156
defer ts.Close()
154157

155158
var clientBuffer bytes.Buffer
156-
client := api.NewClient(api.ClientOpts{Endpoint: ts.URL, Out: &clientBuffer})
159+
u, _ := url.ParseRequestURI(ts.URL)
160+
client := api.NewClient(api.ClientOpts{EndpointURL: u, Out: &clientBuffer})
157161

158162
rf := &archiveRegistry{
159163
client: client,
@@ -193,7 +197,8 @@ func TestArchive_Ensure(t *testing.T) {
193197
defer ts.Close()
194198

195199
var clientBuffer bytes.Buffer
196-
client := api.NewClient(api.ClientOpts{Endpoint: ts.URL, Out: &clientBuffer})
200+
u, _ := url.ParseRequestURI(ts.URL)
201+
client := api.NewClient(api.ClientOpts{EndpointURL: u, Out: &clientBuffer})
197202

198203
rf := &archiveRegistry{
199204
client: client,
@@ -262,7 +267,8 @@ func TestArchive_Ensure(t *testing.T) {
262267
defer ts.Close()
263268

264269
var clientBuffer bytes.Buffer
265-
client := api.NewClient(api.ClientOpts{Endpoint: ts.URL, Out: &clientBuffer})
270+
u, _ := url.ParseRequestURI(ts.URL)
271+
client := api.NewClient(api.ClientOpts{EndpointURL: u, Out: &clientBuffer})
266272

267273
rf := &archiveRegistry{
268274
client: client,

0 commit comments

Comments
 (0)