4
4
"context"
5
5
"crypto/tls"
6
6
"crypto/x509"
7
+ "errors"
7
8
"fmt"
8
9
"io/ioutil"
9
10
"net/http"
@@ -16,7 +17,6 @@ import (
16
17
"github.com/int128/oauth2cli/e2e_test/authserver"
17
18
"golang.org/x/oauth2"
18
19
"golang.org/x/sync/errgroup"
19
- "golang.org/x/xerrors"
20
20
)
21
21
22
22
func TestGetToken (t * testing.T ) {
@@ -181,7 +181,7 @@ func successfulTest(t *testing.T, cfg oauth2cli.Config, h *authserver.Handler) {
181
181
case to := <- openBrowserCh :
182
182
status , body , err := openBrowserRequest (to )
183
183
if err != nil {
184
- return xerrors .Errorf ("could not open browser request: %w" , err )
184
+ return fmt .Errorf ("could not open browser request: %w" , err )
185
185
}
186
186
t .Logf ("got response body: %s" , body )
187
187
if status != 200 {
@@ -192,14 +192,14 @@ func successfulTest(t *testing.T, cfg oauth2cli.Config, h *authserver.Handler) {
192
192
}
193
193
return nil
194
194
case <- ctx .Done ():
195
- return xerrors .Errorf ("context done while waiting for opening browser: %w" , ctx .Err ())
195
+ return fmt .Errorf ("context done while waiting for opening browser: %w" , ctx .Err ())
196
196
}
197
197
})
198
198
eg .Go (func () error {
199
199
// Start a local server and get a token.
200
200
token , err := oauth2cli .GetToken (ctx , cfg )
201
201
if err != nil {
202
- return xerrors .Errorf ("could not get a token: %w" , err )
202
+ return fmt .Errorf ("could not get a token: %w" , err )
203
203
}
204
204
if "ACCESS_TOKEN" != token .AccessToken {
205
205
t .Errorf ("AccessToken wants %s but %s" , "ACCESS_TOKEN" , token .AccessToken )
@@ -243,22 +243,22 @@ func errorAuthorizationResponseTest(t *testing.T, cfg oauth2cli.Config) {
243
243
case to := <- openBrowserCh :
244
244
status , body , err := openBrowserRequest (to )
245
245
if err != nil {
246
- return xerrors .Errorf ("could not open browser request: %w" , err )
246
+ return fmt .Errorf ("could not open browser request: %w" , err )
247
247
}
248
248
t .Logf ("got response body: %s" , body )
249
249
if status != 500 {
250
250
t .Errorf ("status wants 500 but %d" , status )
251
251
}
252
252
return nil
253
253
case <- ctx .Done ():
254
- return xerrors .Errorf ("context done while waiting for opening browser: %w" , ctx .Err ())
254
+ return fmt .Errorf ("context done while waiting for opening browser: %w" , ctx .Err ())
255
255
}
256
256
})
257
257
eg .Go (func () error {
258
258
// Start a local server and get a token.
259
259
_ , err := oauth2cli .GetToken (ctx , cfg )
260
260
if err == nil {
261
- return xerrors .New ("GetToken wants error but was nil" )
261
+ return errors .New ("GetToken wants error but was nil" )
262
262
}
263
263
t .Logf ("expected error: %s" , err )
264
264
return nil
@@ -297,7 +297,7 @@ func errorTokenResponseTest(t *testing.T, cfg oauth2cli.Config) {
297
297
case to := <- openBrowserCh :
298
298
status , body , err := openBrowserRequest (to )
299
299
if err != nil {
300
- return xerrors .Errorf ("could not open browser request: %w" , err )
300
+ return fmt .Errorf ("could not open browser request: %w" , err )
301
301
}
302
302
t .Logf ("got response body: %s" , body )
303
303
if status != 200 {
@@ -308,14 +308,14 @@ func errorTokenResponseTest(t *testing.T, cfg oauth2cli.Config) {
308
308
}
309
309
return nil
310
310
case <- ctx .Done ():
311
- return xerrors .Errorf ("context done while waiting for opening browser: %w" , ctx .Err ())
311
+ return fmt .Errorf ("context done while waiting for opening browser: %w" , ctx .Err ())
312
312
}
313
313
})
314
314
eg .Go (func () error {
315
315
// Start a local server and get a token.
316
316
_ , err := oauth2cli .GetToken (ctx , cfg )
317
317
if err == nil {
318
- return xerrors .New ("GetToken wants error but nil" )
318
+ return errors .New ("GetToken wants error but nil" )
319
319
}
320
320
t .Logf ("expected error: %s" , err )
321
321
return nil
@@ -338,7 +338,7 @@ func openBrowserRequest(url string) (int, string, error) {
338
338
certPool := x509 .NewCertPool ()
339
339
data , err := ioutil .ReadFile ("testdata/ca.pem" )
340
340
if err != nil {
341
- return 0 , "" , xerrors .Errorf ("could not read certificate authority: %w" , err )
341
+ return 0 , "" , fmt .Errorf ("could not read certificate authority: %w" , err )
342
342
}
343
343
if ! certPool .AppendCertsFromPEM (data ) {
344
344
return 0 , "" , fmt .Errorf ("could not append certificate data" )
@@ -348,12 +348,12 @@ func openBrowserRequest(url string) (int, string, error) {
348
348
client := & http.Client {Transport : & http.Transport {TLSClientConfig : & tls.Config {RootCAs : certPool }}}
349
349
resp , err := client .Get (url )
350
350
if err != nil {
351
- return 0 , "" , xerrors .Errorf ("could not send a request: %w" , err )
351
+ return 0 , "" , fmt .Errorf ("could not send a request: %w" , err )
352
352
}
353
353
defer resp .Body .Close ()
354
354
b , err := ioutil .ReadAll (resp .Body )
355
355
if err != nil {
356
- return resp .StatusCode , "" , xerrors .Errorf ("could not read response body: %w" , err )
356
+ return resp .StatusCode , "" , fmt .Errorf ("could not read response body: %w" , err )
357
357
}
358
358
return resp .StatusCode , string (b ), nil
359
359
}
0 commit comments