| OLD | NEW |
| 1 // Copyright 2017 The LUCI Authors. All rights reserved. | 1 // Copyright 2017 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package localauth | 5 package localauth |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "encoding/json" | 9 "encoding/json" |
| 10 "fmt" | 10 "fmt" |
| 11 "io" | 11 "io" |
| 12 "io/ioutil" | 12 "io/ioutil" |
| 13 "net/http" | 13 "net/http" |
| 14 "strings" | 14 "strings" |
| 15 "testing" | 15 "testing" |
| 16 "time" | 16 "time" |
| 17 | 17 |
| 18 "golang.org/x/net/context" | 18 "golang.org/x/net/context" |
| 19 "golang.org/x/oauth2" | 19 "golang.org/x/oauth2" |
| 20 | 20 |
| 21 "github.com/luci/luci-go/common/clock" | 21 "github.com/luci/luci-go/common/clock" |
| 22 "github.com/luci/luci-go/common/clock/testclock" | 22 "github.com/luci/luci-go/common/clock/testclock" |
| 23 "github.com/luci/luci-go/common/errors" | 23 "github.com/luci/luci-go/common/errors" |
| 24 "github.com/luci/luci-go/common/retry" |
| 24 "github.com/luci/luci-go/lucictx" | 25 "github.com/luci/luci-go/lucictx" |
| 25 | 26 |
| 26 . "github.com/luci/luci-go/common/testing/assertions" | 27 . "github.com/luci/luci-go/common/testing/assertions" |
| 27 . "github.com/smartystreets/goconvey/convey" | 28 . "github.com/smartystreets/goconvey/convey" |
| 28 ) | 29 ) |
| 29 | 30 |
| 30 func TestServerLifecycle(t *testing.T) { | 31 func TestServerLifecycle(t *testing.T) { |
| 31 t.Parallel() | 32 t.Parallel() |
| 32 | 33 |
| 33 ctx := context.Background() | 34 ctx := context.Background() |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 | 256 |
| 256 Convey("Token generator returns ErrorWithCode", func() { | 257 Convey("Token generator returns ErrorWithCode", func() { |
| 257 responses <- errWithCode{ | 258 responses <- errWithCode{ |
| 258 error: fmt.Errorf("with code"), | 259 error: fmt.Errorf("with code"), |
| 259 code: 123, | 260 code: 123, |
| 260 } | 261 } |
| 261 So(call(goodRequest()), ShouldEqual, `HTTP 200 (json): {
"error_code":123,"error_message":"with code"}`) | 262 So(call(goodRequest()), ShouldEqual, `HTTP 200 (json): {
"error_code":123,"error_message":"with code"}`) |
| 262 }) | 263 }) |
| 263 | 264 |
| 264 Convey("Token generator returns transient error", func() { | 265 Convey("Token generator returns transient error", func() { |
| 265 » » » responses <- errors.WrapTransient(fmt.Errorf("transient"
)) | 266 » » » responses <- errors.New("transient", retry.Tag) |
| 266 So(call(goodRequest()), ShouldEqual, `HTTP 500: Transien
t error - transient`) | 267 So(call(goodRequest()), ShouldEqual, `HTTP 500: Transien
t error - transient`) |
| 267 }) | 268 }) |
| 268 }) | 269 }) |
| 269 } | 270 } |
| 270 | 271 |
| 271 type errWithCode struct { | 272 type errWithCode struct { |
| 272 error | 273 error |
| 273 code int | 274 code int |
| 274 } | 275 } |
| 275 | 276 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 panic(err) | 315 panic(err) |
| 315 } | 316 } |
| 316 | 317 |
| 317 tp := "" | 318 tp := "" |
| 318 if resp.Header.Get("Content-Type") == "application/json; charset=utf-8"
{ | 319 if resp.Header.Get("Content-Type") == "application/json; charset=utf-8"
{ |
| 319 tp = " (json)" | 320 tp = " (json)" |
| 320 } | 321 } |
| 321 | 322 |
| 322 return fmt.Sprintf("HTTP %d%s: %s", resp.StatusCode, tp, strings.TrimSpa
ce(string(blob))) | 323 return fmt.Sprintf("HTTP %d%s: %s", resp.StatusCode, tp, strings.TrimSpa
ce(string(blob))) |
| 323 } | 324 } |
| OLD | NEW |