Skip to content

Commit

Permalink
fix: increase http timeout over the cloudflare client (#13)
Browse files Browse the repository at this point in the history
* fix: increase http timeout to cloudflare client

* fix: const error msg
  • Loading branch information
amalucelli authored and wwadge committed Aug 4, 2019
1 parent 31ec030 commit c9cb08f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/cloudflare/cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Cloudflare struct {
Client http.Client
}

// New returns a Cloudflare client
func New(apiKey, apiEmail string) Cloudflare {
if apiKey == "" || apiEmail == "" {
panic(errNoAuthorization)
Expand All @@ -39,7 +40,7 @@ func New(apiKey, apiEmail string) Cloudflare {
AuthKey: apiKey,
AuthEmail: apiEmail,
Client: http.Client{
Timeout: time.Second * 5,
Timeout: time.Second * 30,
},
}
return client
Expand Down
47 changes: 47 additions & 0 deletions internal/cloudflare/cloudflare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,59 @@ package cloudflare

import (
"fmt"
"net/http"
"os"
"reflect"
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func TestNew(t *testing.T) {
type args struct {
apiKey string
apiEmail string
}
tests := []struct {
name string
args args
want Cloudflare
}{
{
"NewCloudFlareClient",
args{
"key",
"email",
},
Cloudflare{
API: "https://api.cloudflare.com/client/v4",
AuthKey: "key",
AuthEmail: "email",
Client: http.Client{
Timeout: time.Second * 30,
},
},
},
}
t.Run("NewClientApiEmpty", func(t *testing.T) {
assert.PanicsWithValue(t, errNoAuthorization, func() { New("", "email") })
})
t.Run("NewClientEmailEmpty", func(t *testing.T) {
assert.PanicsWithValue(t, errNoAuthorization, func() { New("api", "") })
})
t.Run("NewClientWithApiAndEmailEmpty", func(t *testing.T) {
assert.PanicsWithValue(t, errNoAuthorization, func() { New("", "") })
})
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := New(tt.args.apiKey, tt.args.apiEmail); !reflect.DeepEqual(got, tt.want) {
t.Errorf("got %v, want %v", got, tt.want)
}
})
}
}

func TestCloudflare_Zones(t *testing.T) {

// fail case
Expand Down

0 comments on commit c9cb08f

Please sign in to comment.