Skip to content

Commit 461dd8f

Browse files
committed
test(go): refactor flaky auth test
1 parent 0297a82 commit 461dd8f

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

pkg/server/auth/auth_test.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -342,25 +342,16 @@ func TestRateLimit(t *testing.T) {
342342
s.Close()
343343
})
344344

345-
res1, err := http.Post(s.URL+"/oauth2/sign_in", "application/json", bytes.NewReader([]byte(`{"password":"my-secret-password"}`)))
345+
resp, err := http.Post(s.URL+"/oauth2/sign_in", "application/json", bytes.NewReader([]byte(`{"password":"bad-password"}`)))
346346
g.Expect(err).NotTo(HaveOccurred())
347-
g.Expect(res1).To(HaveHTTPStatus(http.StatusOK))
347+
g.Expect(resp).To(HaveHTTPStatus(http.StatusUnauthorized))
348348

349-
g.Eventually(func() (*http.Response, error) {
349+
goodSignIn := func() (*http.Response, error) {
350350
return http.Post(s.URL+"/oauth2/sign_in", "application/json", bytes.NewReader([]byte(`{"password":"my-secret-password"}`)))
351-
}).Should(HaveHTTPStatus(http.StatusTooManyRequests))
352-
353-
time.Sleep(time.Second)
354-
355-
res3, err := http.Post(s.URL+"/oauth2/sign_in", "application/json", bytes.NewReader([]byte(`{"password":"my-secret-password"}`)))
356-
g.Expect(err).NotTo(HaveOccurred())
357-
g.Expect(res3).To(HaveHTTPStatus(http.StatusOK))
358-
351+
}
352+
g.Eventually(goodSignIn).Should(HaveHTTPStatus(http.StatusTooManyRequests))
359353
time.Sleep(time.Second)
360-
361-
res4, err := http.Post(s.URL+"/oauth2/sign_in", "application/json", bytes.NewReader([]byte(`{"password":"bad-password"}`)))
362-
g.Expect(err).NotTo(HaveOccurred())
363-
g.Expect(res4).To(HaveHTTPStatus(http.StatusUnauthorized))
354+
g.Expect(goodSignIn()).To(HaveHTTPStatus(http.StatusOK))
364355
}
365356

366357
func TestUserPrincipalValid(t *testing.T) {

0 commit comments

Comments
 (0)