Added client timeout because http.DefaultClient doesn't have timeout
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -55,9 +56,11 @@ type Client struct {
|
||||
// New creates a client object
|
||||
func New(secret string) *Client {
|
||||
client := &Client{
|
||||
URL: getSandboxURL(),
|
||||
Secret: secret,
|
||||
httpCli: http.DefaultClient,
|
||||
URL: getSandboxURL(),
|
||||
Secret: secret,
|
||||
httpCli: &http.Client{
|
||||
Timeout: 10 * time.Second,
|
||||
},
|
||||
}
|
||||
if os.Getenv("IAP_ENVIRONMENT") == "production" {
|
||||
client.URL = ProductionURL
|
||||
|
||||
@@ -60,9 +60,11 @@ func TestHandle400Error(t *testing.T) {
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
expected := &Client{
|
||||
URL: SandboxURL,
|
||||
Secret: "developerSecret",
|
||||
httpCli: http.DefaultClient,
|
||||
URL: SandboxURL,
|
||||
Secret: "developerSecret",
|
||||
httpCli: &http.Client{
|
||||
Timeout: 10 * time.Second,
|
||||
},
|
||||
}
|
||||
|
||||
actual := New("developerSecret")
|
||||
@@ -73,9 +75,11 @@ func TestNew(t *testing.T) {
|
||||
|
||||
func TestNewWithEnvironment(t *testing.T) {
|
||||
expected := &Client{
|
||||
URL: ProductionURL,
|
||||
Secret: "developerSecret",
|
||||
httpCli: http.DefaultClient,
|
||||
URL: ProductionURL,
|
||||
Secret: "developerSecret",
|
||||
httpCli: &http.Client{
|
||||
Timeout: 10 * time.Second,
|
||||
},
|
||||
}
|
||||
|
||||
os.Setenv("IAP_ENVIRONMENT", "production")
|
||||
|
||||
Reference in New Issue
Block a user