forked from miniflux/v2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http client: remove dependency on global config options
- Loading branch information
Showing
7 changed files
with
148 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2020 Frédéric Guillot. All rights reserved. | ||
// Use of this source code is governed by the Apache 2.0 | ||
// license that can be found in the LICENSE file. | ||
|
||
package client // import "miniflux.app/http/client" | ||
|
||
import "testing" | ||
|
||
func TestClientWithDelay(t *testing.T) { | ||
clt := New("http://httpbin.org/delay/5") | ||
clt.ClientTimeout = 1 | ||
_, err := clt.Get() | ||
if err == nil { | ||
t.Fatal(`The client should stops after 1 second`) | ||
} | ||
} | ||
|
||
func TestClientWithError(t *testing.T) { | ||
clt := New("http://httpbin.org/status/502") | ||
clt.ClientTimeout = 1 | ||
response, err := clt.Get() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if response.StatusCode != 502 { | ||
t.Fatalf(`Unexpected response status code: %d`, response.StatusCode) | ||
} | ||
|
||
if !response.HasServerFailure() { | ||
t.Fatal(`A 500 error is considered as server failure`) | ||
} | ||
} | ||
|
||
func TestClientWithResponseTooLarge(t *testing.T) { | ||
clt := New("http://httpbin.org/bytes/100") | ||
clt.ClientMaxBodySize = 10 | ||
_, err := clt.Get() | ||
if err == nil { | ||
t.Fatal(`The client should fails when reading a response too large`) | ||
} | ||
} | ||
|
||
func TestClientWithBasicAuth(t *testing.T) { | ||
clt := New("http://httpbin.org/basic-auth/testuser/testpassword") | ||
clt.WithCredentials("testuser", "testpassword") | ||
_, err := clt.Get() | ||
if err != nil { | ||
t.Fatalf(`The client should be authenticated successfully: %v`, err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.