Skip to content

Commit

Permalink
Add errorcode and message for netext.BlackListedIPError
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Feb 8, 2019
1 parent 278422b commit 9baec92
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions js/modules/k6/http/error_codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net"
"syscall"

"github.com/loadimpact/k6/lib/netext"
"github.com/pkg/errors"
"golang.org/x/net/http2"
)
Expand All @@ -22,6 +23,7 @@ const (
// DNS errors
defaultDNSErrorCode errCode = 1100
dnsNoSuchHostErrorCode errCode = 1101
blackListedIpErrorCode errCode = 1110
// tcp errors
defaultTCPErrorCode errCode = 1200
tcpBrokenPipeErrorCode errCode = 1201
Expand All @@ -43,6 +45,7 @@ var customErrorMsgMap = map[errCode]string{
tcpDialRefusedErrorCode: "dial: connection refused",
tcpBrokenPipeErrorCode: "write: broken pipe",
dnsNoSuchHostErrorCode: "lookup: no such host",
blackListedIpErrorCode: "ip is blacklisted",
http2GoAwayErrorCode: "http2: received GoAway",
http2StreamErrorCode: "http2: stream error",
http2ConnectionErrorCode: "http2: connection error",
Expand All @@ -58,6 +61,8 @@ func errorCodeForError(err error) errCode {
default:
return defaultDNSErrorCode
}
case netext.BlackListedIPError:
return blackListedIpErrorCode
case *http2.GoAwayError:
// TODO: Add different error for all errcode for goaway
return http2GoAwayErrorCode
Expand Down
9 changes: 9 additions & 0 deletions js/modules/k6/http/error_codes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"syscall"
"testing"

"github.com/loadimpact/k6/lib/netext"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
"golang.org/x/net/http2"
Expand Down Expand Up @@ -50,6 +51,14 @@ func TestDNSErrors(t *testing.T) {
testMapOfErrorCodes(t, testTable)
}

func TestBlackListedIPError(t *testing.T) {
var err = netext.BlackListedIPError{}
testErrorCode(t, blackListedIpErrorCode, err)
var response = &Response{}
response.setErrorCode(blackListedIpErrorCode, err)
require.NotEqual(t, err.Error(), response.Error)
}

type timeoutError bool

func (t timeoutError) Timeout() bool {
Expand Down

0 comments on commit 9baec92

Please sign in to comment.