@@ -3,7 +3,6 @@ package main
33import (
44 "context"
55 "fmt"
6- "net/url"
76 "testing"
87
98 "github.com/sourcegraph/src-cli/internal/oauth"
@@ -18,12 +17,12 @@ func TestResolveAuthToken(t *testing.T) {
1817 newOAuthTokenRefresher = func (* oauth.Token ) oauthTokenRefresher {
1918 newRefresherCalled = true
2019 return fakeOAuthTokenRefresher {}
21- }
20+ }
2221
23- token , err := resolveAuthToken (context .Background (), & config {
24- accessToken : "access-token" ,
25- endpointURL : mustParseURL ( t , "https://example.com" ) ,
26- })
22+ token , err := resolveAuthToken (context .Background (), & config {
23+ AccessToken : "access-token" ,
24+ Endpoint : "https://example.com" ,
25+ })
2726 if err != nil {
2827 t .Fatal (err )
2928 }
@@ -39,19 +38,19 @@ func TestResolveAuthToken(t *testing.T) {
3938 reset := stubAuthTokenDependencies (t )
4039 defer reset ()
4140
42- loadOAuthToken = func (context.Context , * url. URL ) (* oauth.Token , error ) {
43- return & oauth.Token {
44- AccessToken : "oauth-token" ,
45- }, nil
41+ loadOAuthToken = func (context.Context , string ) (* oauth.Token , error ) {
42+ return & oauth.Token {
43+ AccessToken : "oauth-token" ,
44+ }, nil
4645 }
4746
4847 newOAuthTokenRefresher = func (* oauth.Token ) oauthTokenRefresher {
4948 return fakeOAuthTokenRefresher {token : oauth.Token {AccessToken : "oauth-token" }}
50- }
49+ }
5150
52- token , err := resolveAuthToken (context .Background (), & config {
53- endpointURL : mustParseURL ( t , "https://example.com" ) ,
54- })
51+ token , err := resolveAuthToken (context .Background (), & config {
52+ Endpoint : "https://example.com" ,
53+ })
5554 if err != nil {
5655 t .Fatal (err )
5756 }
@@ -64,17 +63,17 @@ func TestResolveAuthToken(t *testing.T) {
6463 reset := stubAuthTokenDependencies (t )
6564 defer reset ()
6665
67- loadOAuthToken = func (context.Context , * url. URL ) (* oauth.Token , error ) {
68- return & oauth.Token {AccessToken : "old-token" }, nil
69- }
66+ loadOAuthToken = func (context.Context , string ) (* oauth.Token , error ) {
67+ return & oauth.Token {AccessToken : "old-token" }, nil
68+ }
7069
7170 newOAuthTokenRefresher = func (* oauth.Token ) oauthTokenRefresher {
7271 return fakeOAuthTokenRefresher {token : oauth.Token {AccessToken : "new-token" }}
73- }
72+ }
7473
75- token , err := resolveAuthToken (context .Background (), & config {
76- endpointURL : mustParseURL ( t , "https://example.com" ) ,
77- })
74+ token , err := resolveAuthToken (context .Background (), & config {
75+ Endpoint : "https://example.com" ,
76+ })
7877 if err != nil {
7978 t .Fatal (err )
8079 }
@@ -87,20 +86,20 @@ func TestResolveAuthToken(t *testing.T) {
8786 reset := stubAuthTokenDependencies (t )
8887 defer reset ()
8988
90- loadOAuthToken = func (context.Context , * url. URL ) (* oauth.Token , error ) {
91- return & oauth.Token {AccessToken : "old-token" }, nil
92- }
89+ loadOAuthToken = func (context.Context , string ) (* oauth.Token , error ) {
90+ return & oauth.Token {AccessToken : "old-token" }, nil
91+ }
9392 newOAuthTokenRefresher = func (* oauth.Token ) oauthTokenRefresher {
9493 return fakeOAuthTokenRefresher {err : fmt .Errorf ("refresh failed" )}
9594 }
9695
97- _ , err := resolveAuthToken (context .Background (), & config {
98- endpointURL : mustParseURL (t , "https://example.com" ),
96+ _ , err := resolveAuthToken (context .Background (), & config {
97+ Endpoint : "https://example.com" ,
98+ })
99+ if err == nil {
100+ t .Fatal ("expected error" )
101+ }
99102 })
100- if err == nil {
101- t .Fatal ("expected error" )
102- }
103- })
104103}
105104
106105func stubAuthTokenDependencies (t * testing.T ) func () {
0 commit comments