mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
refactor(http): implement shared transport and clients (#1288)
* fix(http): flip to a shared transport and clients * nice threads * that is terrible * fake uri for magnet * lazy locking * why bother with r's * flip magic params to struct * refactor(http-clients): use separate clients with shared transport * refactor(http-clients): add missing license header * refactor(http-clients): defer and fix errors --------- Co-authored-by: ze0s <ze0s@riseup.net>
This commit is contained in:
parent
2a4fb7750b
commit
3234f0d919
48 changed files with 537 additions and 391 deletions
|
@ -91,6 +91,8 @@ func setupAuthHandler() {
|
|||
}
|
||||
|
||||
func TestAuthHandlerLogin(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
logger := zerolog.Nop()
|
||||
encoder := encoder{}
|
||||
cookieStore := sessions.NewCookieStore([]byte("test"))
|
||||
|
@ -141,6 +143,8 @@ func TestAuthHandlerLogin(t *testing.T) {
|
|||
log.Fatalf("Error occurred: %v", err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
// check for response, here we'll just check for 204 NoContent
|
||||
if status := resp.StatusCode; status != http.StatusNoContent {
|
||||
t.Errorf("login: handler returned wrong status code: got %v want %v", status, http.StatusNoContent)
|
||||
|
@ -152,6 +156,8 @@ func TestAuthHandlerLogin(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAuthHandlerValidateOK(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
logger := zerolog.Nop()
|
||||
encoder := encoder{}
|
||||
cookieStore := sessions.NewCookieStore([]byte("test"))
|
||||
|
@ -202,6 +208,8 @@ func TestAuthHandlerValidateOK(t *testing.T) {
|
|||
log.Fatalf("Error occurred: %v", err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
// check for response, here we'll just check for 204 NoContent
|
||||
if status := resp.StatusCode; status != http.StatusNoContent {
|
||||
t.Errorf("login: handler returned wrong status code: got %v want %v", status, http.StatusNoContent)
|
||||
|
@ -217,12 +225,16 @@ func TestAuthHandlerValidateOK(t *testing.T) {
|
|||
log.Fatalf("Error occurred: %v", err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
if status := resp.StatusCode; status != http.StatusNoContent {
|
||||
t.Errorf("validate: handler returned wrong status code: got %v want %v", status, http.StatusNoContent)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuthHandlerValidateBad(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
logger := zerolog.Nop()
|
||||
encoder := encoder{}
|
||||
cookieStore := sessions.NewCookieStore([]byte("test"))
|
||||
|
@ -264,12 +276,16 @@ func TestAuthHandlerValidateBad(t *testing.T) {
|
|||
log.Fatalf("Error occurred: %v", err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
if status := resp.StatusCode; status != http.StatusUnauthorized {
|
||||
t.Errorf("validate: handler returned wrong status code: got %v want %v", status, http.StatusUnauthorized)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuthHandlerLoginBad(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
logger := zerolog.Nop()
|
||||
encoder := encoder{}
|
||||
cookieStore := sessions.NewCookieStore([]byte("test"))
|
||||
|
@ -310,6 +326,8 @@ func TestAuthHandlerLoginBad(t *testing.T) {
|
|||
log.Fatalf("Error occurred: %v", err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
// check for response, here we'll just check for 204 NoContent
|
||||
if status := resp.StatusCode; status != http.StatusUnauthorized {
|
||||
t.Errorf("handler returned wrong status code: got %v want %v", status, http.StatusUnauthorized)
|
||||
|
@ -317,6 +335,8 @@ func TestAuthHandlerLoginBad(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAuthHandlerLogout(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
logger := zerolog.Nop()
|
||||
encoder := encoder{}
|
||||
cookieStore := sessions.NewCookieStore([]byte("test"))
|
||||
|
@ -367,6 +387,8 @@ func TestAuthHandlerLogout(t *testing.T) {
|
|||
log.Fatalf("Error occurred: %v", err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
// check for response, here we'll just check for 204 NoContent
|
||||
if status := resp.StatusCode; status != http.StatusNoContent {
|
||||
t.Errorf("login: handler returned wrong status code: got %v want %v", status, http.StatusNoContent)
|
||||
|
@ -382,6 +404,8 @@ func TestAuthHandlerLogout(t *testing.T) {
|
|||
log.Fatalf("Error occurred: %v", err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
if status := resp.StatusCode; status != http.StatusNoContent {
|
||||
t.Errorf("validate: handler returned wrong status code: got %v want %v", status, http.StatusNoContent)
|
||||
}
|
||||
|
@ -392,6 +416,8 @@ func TestAuthHandlerLogout(t *testing.T) {
|
|||
log.Fatalf("Error occurred: %v", err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
if status := resp.StatusCode; status != http.StatusNoContent {
|
||||
t.Errorf("validate: handler returned wrong status code: got %v want %v", status, http.StatusNoContent)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue