chore: extract find cookie #181
This commit is contained in:
20
main_test.go
20
main_test.go
@@ -49,8 +49,6 @@ func TestHandleSignIn(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error creating request: %v", err)
|
t.Fatalf("Error creating request: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the content type to application/x-www-form-urlencoded
|
|
||||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
|
||||||
resp, err := httpClient.Do(req)
|
resp, err := httpClient.Do(req)
|
||||||
@@ -62,13 +60,7 @@ func TestHandleSignIn(t *testing.T) {
|
|||||||
t.Fatalf("Expected status code 303, got %d", resp.StatusCode)
|
t.Fatalf("Expected status code 303, got %d", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
var cookie *http.Cookie
|
cookie := findCookie(resp, "id")
|
||||||
for _, c := range resp.Cookies() {
|
|
||||||
if c.Name == "id" {
|
|
||||||
cookie = c
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if cookie == nil {
|
if cookie == nil {
|
||||||
t.Fatalf("No session cookie found")
|
t.Fatalf("No session cookie found")
|
||||||
} else if cookie.SameSite != http.SameSiteStrictMode || cookie.HttpOnly != true || cookie.Secure != true {
|
} else if cookie.SameSite != http.SameSiteStrictMode || cookie.HttpOnly != true || cookie.Secure != true {
|
||||||
@@ -77,6 +69,16 @@ func TestHandleSignIn(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findCookie(resp *http.Response, name string) *http.Cookie {
|
||||||
|
for _, cookie := range resp.Cookies() {
|
||||||
|
if cookie.Name == name {
|
||||||
|
return cookie
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func setupIntegrationTest(t *testing.T, port string) (*sql.DB, context.Context) {
|
func setupIntegrationTest(t *testing.T, port string) (*sql.DB, context.Context) {
|
||||||
ctx, done := context.WithCancel(context.Background())
|
ctx, done := context.WithCancel(context.Background())
|
||||||
t.Cleanup(done)
|
t.Cleanup(done)
|
||||||
|
|||||||
Reference in New Issue
Block a user