(t *testing.T)
| 3423 | } |
| 3424 | |
| 3425 | func TestContextSetCookieData(t *testing.T) { |
| 3426 | c, _ := CreateTestContext(httptest.NewRecorder()) |
| 3427 | c.SetSameSite(http.SameSiteLaxMode) |
| 3428 | var setCookie string |
| 3429 | |
| 3430 | // Basic cookie settings |
| 3431 | cookie := &http.Cookie{ |
| 3432 | Name: "user", |
| 3433 | Value: "gin", |
| 3434 | MaxAge: 1, |
| 3435 | Path: "/", |
| 3436 | Domain: "localhost", |
| 3437 | Secure: true, |
| 3438 | HttpOnly: true, |
| 3439 | } |
| 3440 | c.SetCookieData(cookie) |
| 3441 | setCookie = c.Writer.Header().Get("Set-Cookie") |
| 3442 | assert.Contains(t, setCookie, "user=gin") |
| 3443 | assert.Contains(t, setCookie, "Path=/") |
| 3444 | assert.Contains(t, setCookie, "Domain=localhost") |
| 3445 | assert.Contains(t, setCookie, "Max-Age=1") |
| 3446 | assert.Contains(t, setCookie, "HttpOnly") |
| 3447 | assert.Contains(t, setCookie, "Secure") |
| 3448 | // SameSite=Lax might be omitted in Go 1.24+ as it's the default |
| 3449 | // assert.Contains(t, setCookie, "SameSite=Lax") |
| 3450 | |
| 3451 | // Test that when Path is empty, "/" is automatically set |
| 3452 | cookie = &http.Cookie{ |
| 3453 | Name: "user", |
| 3454 | Value: "gin", |
| 3455 | MaxAge: 1, |
| 3456 | Path: "", |
| 3457 | Domain: "localhost", |
| 3458 | Secure: true, |
| 3459 | HttpOnly: true, |
| 3460 | } |
| 3461 | c.SetCookieData(cookie) |
| 3462 | setCookie = c.Writer.Header().Get("Set-Cookie") |
| 3463 | assert.Contains(t, setCookie, "user=gin") |
| 3464 | assert.Contains(t, setCookie, "Path=/") |
| 3465 | assert.Contains(t, setCookie, "Domain=localhost") |
| 3466 | assert.Contains(t, setCookie, "Max-Age=1") |
| 3467 | assert.Contains(t, setCookie, "HttpOnly") |
| 3468 | assert.Contains(t, setCookie, "Secure") |
| 3469 | // SameSite=Lax might be omitted in Go 1.24+ as it's the default |
| 3470 | // assert.Contains(t, setCookie, "SameSite=Lax") |
| 3471 | |
| 3472 | // Test additional cookie attributes (Expires) |
| 3473 | expireTime := time.Now().Add(24 * time.Hour) |
| 3474 | cookie = &http.Cookie{ |
| 3475 | Name: "user", |
| 3476 | Value: "gin", |
| 3477 | Path: "/", |
| 3478 | Domain: "localhost", |
| 3479 | Expires: expireTime, |
| 3480 | Secure: true, |
| 3481 | HttpOnly: true, |
| 3482 | } |
nothing calls this directly
no test coverage detected