@@ -16,6 +16,15 @@ import (
1616 "github.com/sourcegraph/src-cli/internal/oauth"
1717)
1818
19+ func mustParseURL (t * testing.T , raw string ) * url.URL {
20+ t .Helper ()
21+ u , err := url .Parse (raw )
22+ if err != nil {
23+ t .Fatalf ("failed to parse URL %q: %v" , raw , err )
24+ }
25+ return u
26+ }
27+
1928func TestLogin (t * testing.T ) {
2029 check := func (t * testing.T , cfg * config , endpointArgURL * url.URL ) (output string , err error ) {
2130 t .Helper ()
@@ -72,7 +81,7 @@ func TestLogin(t *testing.T) {
7281 }))
7382 defer s .Close ()
7483
75- u , _ := url . ParseRequestURI ( s .URL )
84+ u := mustParseURL ( t , s .URL )
7685 out , err := check (t , & config {endpointURL : u , accessToken : "x" }, u )
7786 if err != cmderrors .ExitCode1 {
7887 t .Fatal (err )
@@ -90,7 +99,7 @@ func TestLogin(t *testing.T) {
9099 }))
91100 defer s .Close ()
92101
93- u , _ := url . ParseRequestURI ( s .URL )
102+ u := mustParseURL ( t , s .URL )
94103 out , err := check (t , & config {endpointURL : u , accessToken : "x" }, u )
95104 if err != nil {
96105 t .Fatal (err )
@@ -173,17 +182,9 @@ func (f fakeOAuthClient) Refresh(context.Context, *oauth.Token) (*oauth.TokenRes
173182}
174183
175184func TestSelectLoginFlow (t * testing.T ) {
176- mustParseURL := func (s string ) * url.URL {
177- u , err := url .Parse (s )
178- if err != nil {
179- t .Fatal (err )
180- }
181- return u
182- }
183-
184185 t .Run ("uses oauth flow when no access token is configured" , func (t * testing.T ) {
185186 params := loginParams {
186- cfg : & config {endpointURL : mustParseURL ("https://example.com" )},
187+ cfg : & config {endpointURL : mustParseURL (t , "https://example.com" )},
187188 }
188189
189190 if got , _ := selectLoginFlow (params ); got != loginFlowOAuth {
@@ -193,7 +194,7 @@ func TestSelectLoginFlow(t *testing.T) {
193194
194195 t .Run ("uses validation flow when auth exists for the selected endpoint" , func (t * testing.T ) {
195196 params := loginParams {
196- cfg : & config {endpointURL : mustParseURL ("https://example.com" ), accessToken : "x" },
197+ cfg : & config {endpointURL : mustParseURL (t , "https://example.com" ), accessToken : "x" },
197198 }
198199
199200 if got , _ := selectLoginFlow (params ); got != loginFlowValidate {
0 commit comments