Skip to content

Commit

Permalink
check Timeout value of http error
Browse files Browse the repository at this point in the history
  • Loading branch information
utekaravinash committed Mar 6, 2020
1 parent 1eef1e4 commit 7749c41
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"io/ioutil"
"net/http"
"os"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -93,19 +92,26 @@ func TestSetTimeout(t *testing.T) {

client.httpClient = httpClient

// First Request
client.SetTimeout(time.Nanosecond * 1)
_, err1 := client.GetItems(&params)

firstRequestTimedOut := false
if e, ok := err1.(interface{ Timeout() bool }); ok {
firstRequestTimedOut = e.Timeout()
}

// Second Request
client.SetTimeout(time.Hour * 1)
response, _ := client.GetItems(&params)
response, err2 := client.GetItems(&params)

tests := []struct {
name string
expected interface{}
actual interface{}
}{
{"Request Timeout", true, strings.Contains(err1.Error(), "Client.Timeout exceeded while awaiting headers")},
{"Request Completed", 2, len(response.ItemsResult.Items)},
{"1st Request Timeout", true, firstRequestTimedOut},
{"2nd Request Completed", true, err2 == nil && len(response.ItemsResult.Items) == 2},
}

for _, test := range tests {
Expand Down

0 comments on commit 7749c41

Please sign in to comment.