Do not must() write error
refactor: early out for non matching path
@@ -388,13 +388,19 @@ func TestOAuth2_AccessControl(t *testing.T) {
func TestOAuth2_Locking(t *testing.T) {
helper := test.New(t)
- client := newClient()
+ client := test.NewHTTPClient()
token := "token-"
var oauthRequestCount uint32
+
oauthOrigin := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
+ if req.URL.Path != "/oauth2" {
+ rw.WriteHeader(http.StatusBadRequest)
+ return
+ }
+
atomic.AddUint32(&oauthRequestCount, 1)
- if req.URL.Path == "/oauth2" {
+
rw.Header().Set("Content-Type", "application/json")
rw.WriteHeader(http.StatusOK)
@@ -405,16 +411,13 @@ func TestOAuth2_Locking(t *testing.T) {
"expires_in": 1.5
}`)
- // Slow down token request to test locking.
- time.Sleep(1 * time.Second)
+ // Slow down token request
+ time.Sleep(time.Second)
_, werr := rw.Write(body)
- helper.Must(werr)
-
- return
+ if werr != nil {
+ t.Error(werr)
}
-
- rw.WriteHeader(http.StatusBadRequest)
}))
defer oauthOrigin.Close()
